GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — cli/main.go at main · rancher/cli Expand file tree/ Copy pathmain.goMore file actions 165 lines (145 loc) · 4.06 KB / Copy pathmain.goFile metadata and controls165 lines (145 loc) · 4.06 KB 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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 package main import ( "context" "errors" "fmt" "os" "regexp" "strings" "github.com/rancher/cli/cmd" "github.com/rancher/cli/config" "github.com/sirupsen/logrus" "github.com/urfave/cli/v3" ) var VERSION = "dev" var AppHelpTemplate = `{{.Usage}} Usage: {{.Name}} {{if .Flags}}[OPTIONS] {{end}}COMMAND [arg...] Version: {{.Version}} {{if .VisibleFlags}} Options: {{range .VisibleFlags}}{{.}} {{end}}{{end}} Commands: {{range .VisibleCommands}}{{.Name}}{{with .Aliases}}, {{join . ", "}}{{end}}{{ "\t" }}{{.Usage}} {{end}} Run '{{.Name}} COMMAND --help' for more information on a command. ` var CommandHelpTemplate = `{{.Usage}} {{if .Description}}{{.Description}}{{end}} Usage: {{.FullName}} {{if .Flags}}[OPTIONS] {{end}}{{if ne "None" .ArgsUsage}}{{if ne "" .ArgsUsage}}{{.ArgsUsage}}{{else}}[arg...]{{end}}{{end}} {{if .VisibleFlags}}Options:{{range .VisibleFlags}} {{.}}{{end}}{{end}} ` var SubcommandHelpTemplate = `{{.Usage}} {{if .Description}}{{.Description}}{{end}} Usage: {{.FullName}} command{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}} Commands:{{range .VisibleCategories}}{{if .Name}} {{.Name}}:{{end}}{{range .VisibleCommands}} {{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}} {{end}}{{if .VisibleFlags}} Options: {{range .VisibleFlags}}{{.}} {{end}}{{end}} ` func main() { if err := mainErr(); err != nil { logrus.Fatal(err) } } func mainErr() error { cli.CommandHelpTemplate = CommandHelpTemplate cli.SubcommandHelpTemplate = SubcommandHelpTemplate configDir, err := cmd.ConfigDir() if err != nil { return err } rootCmd := &cli.Command{ Name: "rancher", Usage: "Rancher CLI, managing containers one UTF-8 character at a time", Version: VERSION, CustomRootCommandHelpTemplate: AppHelpTemplate, EnableShellCompletion: true, ConfigureShellCompletionCommand: func(cmd *cli.Command) { cmd.Hidden = false }, Before: func(ctx context.Context, c *cli.Command) (context.Context, error) { if c.Bool("debug") { logrus.SetLevel(logrus.DebugLevel) } path := cmd.GetConfigPath(c) warnings, err := config.GetFilePermissionWarnings(path) if err != nil { // We don't want to block the execution of the CLI in that case logrus.Errorf("Unable to verify config file permission: %s. Continuing.", err) } for _, warning := range warnings { logrus.Warning(warning) } return ctx, nil }, Flags: []cli.Flag{ &cli.BoolFlag{ Name: "debug", Usage: "Debug logging", }, &cli.StringFlag{ Name: "config", Aliases: []string{"c"}, Usage: "Path to rancher config", Sources: cli.EnvVars("RANCHER_CONFIG_DIR"), Value: configDir, }, }, Commands: []*cli.Command{ cmd.AuthCommand(), cmd.ClusterCommand(), cmd.ContextCommand(), cmd.InspectCommand(), cmd.KubectlCommand(), cmd.LoginCommand(), cmd.MachineCommand(), cmd.NamespaceCommand(), cmd.NodeCommand(), cmd.ProjectCommand(), cmd.PsCommand(), cmd.ServerCommand(), cmd.SettingsCommand(), cmd.SSHCommand(), cmd.UpCommand(), cmd.WaitCommand(), cmd.CredentialCommand(), }, } parsed, err := parseArgs(os.Args) if err != nil { logrus.Error(err) os.Exit(1) } return rootCmd.Run(context.Background(), parsed) } var singleAlphaLetterRegexp = regexp.MustCompile("[a-zA-Z]") func parseArgs(args []string) ([]string, error) { result := []string{} for _, arg := range args { if strings.HasPrefix(arg, "-") && !strings.HasPrefix(arg, "--") && len(arg) > 1 { for i, c := range arg[1:] { if string(c) == "=" { if i < 1 { return nil, errors.New("invalid input with '-' and '=' flag") } result[len(result)-1] = result[len(result)-1] + arg[i+1:] break } else if singleAlphaLetterRegexp.MatchString(string(c)) { result = append(result, "-"+string(c)) } else { return nil, fmt.Errorf("invalid input %s in flag", string(c)) } } } else { result = append(result, arg) } } return result, nil } |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |