-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
45 lines (38 loc) · 923 Bytes
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright 2020 Fazlul Shahriar. All rights reserved.
// Use of this source code is governed by the
// license that can be found in the LICENSE file.
package cli
import (
"fmt"
"github.com/spf13/cobra"
)
func init() {
var cc configCmd
cmd := &cobra.Command{
Use: "config",
Short: "Get repository or global options",
Long: `Gig uses the same configuration files as git(1).`,
RunE: cc.run,
}
rootCmd.AddCommand(cmd)
cmd.Flags().BoolVarP(&cc.list, "list", "l", false, "List all variables set in config file")
}
type configCmd struct {
list bool
}
func (cc *configCmd) run(_ *cobra.Command, args []string) error {
if !cc.list {
return fmt.Errorf("no flags given")
}
_, r, err := openRepo()
if err != nil {
return err
}
cfg, err := loadRepoConfig(r)
if err != nil {
return err
}
fmt.Printf("user.name=%v\n", cfg.User.Name)
fmt.Printf("user.email=%v\n", cfg.User.Email)
return nil
}