github.com/caos/orbos@v1.5.14-0.20221103111702-e6cd0cea7ad4/cmd/orbctl/print.go (about) 1 // Inspired by https://samrapdev.com/capturing-sensitive-input-with-editor-in-golang-from-the-cli/ 2 3 package main 4 5 import ( 6 "errors" 7 "fmt" 8 9 "github.com/spf13/cobra" 10 ) 11 12 func PrintCommand(getRv GetRootValues) *cobra.Command { 13 14 return &cobra.Command{ 15 Use: "print <path>", 16 Short: "Print the files contents to stdout", 17 Args: cobra.ExactArgs(1), 18 Example: `orbctl file print orbiter.yml`, 19 RunE: func(cmd *cobra.Command, args []string) (err error) { 20 21 file := args[0] 22 23 rv := getRv("print", "", map[string]interface{}{"file": file}) 24 defer rv.ErrFunc(err) 25 26 if !rv.Gitops { 27 return errors.New("print command is only supported with the --gitops flag") 28 } 29 30 if err := initRepo(rv.OrbConfig, rv.GitClient); err != nil { 31 return err 32 } 33 34 fmt.Print(string(rv.GitClient.Read(file))) 35 return nil 36 }, 37 } 38 }