Export returns `export` command
(cfg storage)
| 11 | |
| 12 | // Export returns `export` command |
| 13 | func Export(cfg storage) *cobra.Command { |
| 14 | return &cobra.Command{ |
| 15 | Use: "export [profile]", |
| 16 | Aliases: []string{"e"}, |
| 17 | Short: "Export a profile", |
| 18 | Long: "Export a profile as JSON.", |
| 19 | Args: cobra.ExactArgs(1), |
| 20 | Example: "git-profile export my-profile", |
| 21 | Run: func(cmd *cobra.Command, args []string) { |
| 22 | profile := args[0] |
| 23 | |
| 24 | entries, ok := cfg.Lookup(profile) |
| 25 | if !ok { |
| 26 | ui.PrintErrln(cmd, ui.ErrorStyle, "There is no profile with `%s` name", profile) |
| 27 | os.Exit(0) |
| 28 | } |
| 29 | |
| 30 | data, err := json.Marshal(entries) |
| 31 | if err != nil { |
| 32 | ui.PrintErrln(cmd, ui.ErrorStyle, "Unable to encode profile values: %s", err) |
| 33 | os.Exit(1) |
| 34 | } |
| 35 | |
| 36 | cmd.Println(string(data)) |
| 37 | }, |
| 38 | } |
| 39 | } |