github.com/jenkins-x/jx/v2@v2.1.155/pkg/cmd/get/get_git.go (about) 1 package get 2 3 import ( 4 "github.com/jenkins-x/jx/v2/pkg/cmd/helper" 5 "github.com/spf13/cobra" 6 7 "github.com/jenkins-x/jx/v2/pkg/cmd/opts" 8 "github.com/jenkins-x/jx/v2/pkg/cmd/templates" 9 ) 10 11 // GetGitOptions the command line options 12 type GetGitOptions struct { 13 Options 14 } 15 16 var ( 17 get_git_long = templates.LongDesc(` 18 Display the Git server URLs. 19 20 `) 21 22 get_git_example = templates.Examples(` 23 # List all registered Git server URLs 24 jx get git 25 `) 26 ) 27 28 // NewCmdGetGit creates the command 29 func NewCmdGetGit(commonOpts *opts.CommonOptions) *cobra.Command { 30 options := &GetGitOptions{ 31 Options: Options{ 32 CommonOptions: commonOpts, 33 }, 34 } 35 36 cmd := &cobra.Command{ 37 Use: "git [flags]", 38 Short: "Display the current registered Git service URLs", 39 Long: get_git_long, 40 Example: get_git_example, 41 Aliases: []string{"gitserver"}, 42 Run: func(cmd *cobra.Command, args []string) { 43 options.Cmd = cmd 44 options.Args = args 45 err := options.Run() 46 helper.CheckErr(err) 47 }, 48 } 49 50 return cmd 51 } 52 53 // Run implements this command 54 func (o *GetGitOptions) Run() error { 55 authConfigSvc, err := o.GitAuthConfigService() 56 if err != nil { 57 return err 58 } 59 config := authConfigSvc.Config() 60 61 table := o.CreateTable() 62 table.AddRow("Name", "Kind", "URL") 63 64 for _, s := range config.Servers { 65 kind := s.Kind 66 if kind == "" { 67 kind = "github" 68 } 69 table.AddRow(s.Name, kind, s.URL) 70 } 71 table.Render() 72 return nil 73 }