| 62 | } |
| 63 | |
| 64 | func (c *Cmd) init() { |
| 65 | cobra.OnInitialize(func() { |
| 66 | filename, err := homedir.Expand(c.filename) |
| 67 | if err != nil { |
| 68 | c.PrintErrln(err) |
| 69 | os.Exit(1) |
| 70 | } |
| 71 | |
| 72 | err = c.config.Load(filename) |
| 73 | if err != nil { |
| 74 | c.PrintErrln("Unable to load config:", err) |
| 75 | os.Exit(1) |
| 76 | } |
| 77 | |
| 78 | c.filename = filename |
| 79 | }) |
| 80 | |
| 81 | c.AddCommand( |
| 82 | Add(c.config), |
| 83 | Completion(&c.Command), |
| 84 | Current(c.config, c.git), |
| 85 | Del(c.config), |
| 86 | List(c.config, c.git), |
| 87 | Export(c.config), |
| 88 | Import(c.config), |
| 89 | Use(c.config, c.git), |
| 90 | Unuse(c.config, c.git), |
| 91 | Version(c), |
| 92 | ) |
| 93 | |
| 94 | c.SetOutput(os.Stdout) |
| 95 | c.SetErr(os.Stderr) |
| 96 | |
| 97 | c.PersistentFlags().StringVarP(&c.filename, "config", "c", "~/.gitprofile", "config file") |
| 98 | } |
| 99 | |
| 100 | func multiline(lines ...string) string { |
| 101 | return strings.Join(lines, "\n") |