From 79da64fb2625b7f8704c7c756fee1356fde67de9 Mon Sep 17 00:00:00 2001 From: Episkey <70593980+Episkey-G@users.noreply.github.com> Date: Sun, 27 Apr 2025 13:30:47 +0800 Subject: [PATCH 1/2] feat: externalize UCloud literals to ldflags variables (#91) * feat: externalize UCloud literals to ldflags variables * fix: ucloud.cn to ldflags variables * fix: split combined URL into separate config variables --------- Co-authored-by: run.gu --- base/branding.go | 16 +++++++++++++ base/config.go | 13 ++++++----- base/config_test.go | 27 ++++++++++++---------- base/log.go | 7 +++++- base/util.go | 2 +- cmd/api.go | 4 ++-- cmd/backup.go | 8 +++---- cmd/bandwidth.go | 4 ++-- cmd/completion.go | 8 +++---- cmd/configure.go | 51 +++++++++++++++++++++-------------------- cmd/disk.go | 12 ++++++---- cmd/eip.go | 30 ++++++++++++------------ cmd/ext.go | 6 ++--- cmd/firewall.go | 56 ++++++++++++++++++++++----------------------- cmd/globalssh.go | 12 +++++----- cmd/image.go | 6 ++--- cmd/mysql.go | 16 ++++++------- cmd/pathx.go | 18 +++++++-------- cmd/project.go | 11 +++++---- cmd/region.go | 2 +- cmd/root.go | 14 ++++++------ cmd/signature.go | 5 ++-- cmd/signup.go | 10 ++++---- cmd/uhost.go | 43 ++++++++++++++++++---------------- cmd/ulb.go | 4 ++-- cmd/umem.go | 12 +++++----- cmd/unet.go | 12 +++++----- cmd/util.go | 16 ++++++------- cmd/vpc.go | 20 ++++++++-------- 29 files changed, 240 insertions(+), 205 deletions(-) create mode 100644 base/branding.go diff --git a/base/branding.go b/base/branding.go new file mode 100644 index 0000000000..a154d7774c --- /dev/null +++ b/base/branding.go @@ -0,0 +1,16 @@ +package base + +// 编译时用 -ldflags 覆盖 +var ( + BrandName = "UCloud" + BrandNameLower = "ucloud" + BrandAPIURL = "https://api.ucloud.cn/" + BrandUmountURL = "https://docs.ucloud.cn/storage_cdn/udisk/userguide/umount" + BrandLogURL = "https://das-rpt.ucloud.cn/log" + BrandAuthURL = "https://accountv2.ucloud.cn/authentication" + BrandAccountURL = "https://accountv2.ucloud.cn" + BrandRegisterURL = "https://passport.ucloud.cn/#register" + BrandUhostTypeURL = "https://docs.ucloud.cn/api/uhost-api/uhost_type" + BrandDiskTypeURL = "https://docs.ucloud.cn/api/uhost-api/disk_type" + BrandUserDataURL = "https://docs.ucloud.cn/uhost/guide/metadata/userdata" +) diff --git a/base/config.go b/base/config.go index b4ecb7f72d..298af5c4c2 100644 --- a/base/config.go +++ b/base/config.go @@ -33,7 +33,7 @@ const DefaultTimeoutSec = 15 const DefaultMaxRetryTimes = 3 // DefaultBaseURL location of api server -const DefaultBaseURL = "https://api.ucloud.cn/" +var DefaultBaseURL string // DefaultProfile name of default profile const DefaultProfile = "default" @@ -41,7 +41,7 @@ const DefaultProfile = "default" // Version 版本号 const Version = "0.3.0" -var UserAgent = fmt.Sprintf("UCloud-CLI/%s", Version) +var UserAgent = fmt.Sprintf("%s-CLI/%s", BrandName, Version) var InCloudShell = os.Getenv("CLOUD_SHELL") == "true" @@ -166,7 +166,7 @@ func (p *AggConfig) ConfigBaseURL() error { // ConfigUploadLog agree upload log or not func (p *AggConfig) ConfigUploadLog() error { var input string - fmt.Print("Do you agree to upload log in local file ~/.ucloud/cli.log to help ucloud-cli get better(yes|no):") + fmt.Printf("Do you agree to upload log in local file ~/%s/cli.log to help %s-cli get better(yes|no):", ConfigPath, BrandNameLower) _, err := fmt.Scanf("%s\n", &input) if err != nil { HandleError(err) @@ -342,10 +342,10 @@ func (p *AggConfigManager) Load() error { } if p.activeProfile == "" && len(configMap) > 0 { - return fmt.Errorf("no active config found, run 'ucloud config list' to check") + return fmt.Errorf("no active config found, run '%s config list' to check", BrandNameLower) } if _, ok := credMap[p.activeProfile]; p.activeProfile != "" && !ok { - return fmt.Errorf("profile %s's credential don't exist, run 'ucloud config list' to check", p.activeProfile) + return fmt.Errorf("profile %s's credential don't exist, run '%s config list' to check", p.activeProfile, BrandNameLower) } return nil @@ -544,7 +544,7 @@ func (p *AggConfigManager) GetActiveAggConfig() (*AggConfig, error) { if ac, ok := p.configs[p.activeProfile]; ok { return ac, nil } - return nil, fmt.Errorf("active profile not found. see 'ucloud config list'") + return nil, fmt.Errorf("active profile not found. see '%s config list'", BrandNameLower) } // GetActiveAggConfigName get active config name @@ -847,6 +847,7 @@ func mergeConfigIns(ins *AggConfig) { } func init() { + DefaultBaseURL = fmt.Sprintf("%s", BrandAPIURL) //配置日志 err := initLog() if err != nil { diff --git a/base/config_test.go b/base/config_test.go index 1bb244ee8b..0c2dc9e345 100644 --- a/base/config_test.go +++ b/base/config_test.go @@ -1,14 +1,15 @@ package base import ( + "fmt" "io/ioutil" "os" "testing" ) const cliConfigJSON = `[ - {"project_id":"org-bdks4e","region":"cn-bj2","zone":"cn-bj2-04","base_url":"https://api.ucloud.cn/","timeout_sec":15,"profile":"uweb","active":true}, - {"project_id":"org-oxjwoi","region":"hk","zone":"hk-02","base_url":"https://api.ucloud.cn/","timeout_sec":15,"profile":"test","active":false} + {"project_id":"org-bdks4e","region":"cn-bj2","zone":"cn-bj2-04","base_url":"%s","timeout_sec":15,"profile":"uweb","active":true}, + {"project_id":"org-oxjwoi","region":"hk","zone":"hk-02","base_url":"%s","timeout_sec":15,"profile":"test","active":false} ]` const credentialJSON = `[ @@ -17,28 +18,30 @@ const credentialJSON = `[ ]` func TestAggConfigManager(t *testing.T) { - os.MkdirAll(".ucloud", 0700) - err := ioutil.WriteFile(".ucloud/config.json", []byte(cliConfigJSON), LocalFileMode) + os.MkdirAll(ConfigPath, 0700) + baseURL := fmt.Sprintf("%s", BrandAPIURL) + configJSON := fmt.Sprintf(cliConfigJSON, baseURL, baseURL) + err := ioutil.WriteFile(ConfigPath+"/config.json", []byte(configJSON), LocalFileMode) if err != nil { t.Error(err) } - err = ioutil.WriteFile(".ucloud/credential.json", []byte(credentialJSON), LocalFileMode) + err = ioutil.WriteFile(ConfigPath+"/credential.json", []byte(credentialJSON), LocalFileMode) if err != nil { t.Error(err) } defer func() { - err := os.RemoveAll(".ucloud") + err := os.RemoveAll(ConfigPath) if err != nil { t.Error(err) } }() - configFile, err := os.OpenFile(".ucloud/config.json", os.O_CREATE|os.O_RDONLY, LocalFileMode) + configFile, err := os.OpenFile(ConfigPath+"/config.json", os.O_CREATE|os.O_RDONLY, LocalFileMode) if err != nil { t.Error(err) } - credFile, err := os.OpenFile(".ucloud/credential.json", os.O_CREATE|os.O_RDONLY, LocalFileMode) + credFile, err := os.OpenFile(ConfigPath+"/credential.json", os.O_CREATE|os.O_RDONLY, LocalFileMode) if err != nil { t.Error(err) } @@ -55,20 +58,20 @@ func TestAggConfigManager(t *testing.T) { } func TestEmptyAggConfigManager(t *testing.T) { - os.MkdirAll(".ucloud", 0700) + os.MkdirAll(ConfigPath, 0700) defer func() { - err := os.RemoveAll(".ucloud") + err := os.RemoveAll(ConfigPath) if err != nil { t.Error(err) } }() - configFile, err := os.OpenFile(".ucloud/config.json", os.O_CREATE|os.O_RDONLY, LocalFileMode) + configFile, err := os.OpenFile(ConfigPath+"/config.json", os.O_CREATE|os.O_RDONLY, LocalFileMode) if err != nil { t.Error(err) } - credFile, err := os.OpenFile(".ucloud/credential.json", os.O_CREATE|os.O_RDONLY, LocalFileMode) + credFile, err := os.OpenFile(ConfigPath+"/credential.json", os.O_CREATE|os.O_RDONLY, LocalFileMode) if err != nil { t.Error(err) } diff --git a/base/log.go b/base/log.go index da036404df..d22f1685e3 100644 --- a/base/log.go +++ b/base/log.go @@ -18,7 +18,12 @@ import ( "github.com/ucloud/ucloud-sdk-go/ucloud/version" ) -const DefaultDasURL = "https://das-rpt.ucloud.cn/log" +// DefaultDasURL location of das server +var DefaultDasURL string + +func init() { + DefaultDasURL = fmt.Sprintf("%s", BrandLogURL) +} // Logger 日志 var logger *log.Logger diff --git a/base/util.go b/base/util.go index a49f75878b..cdac8cff35 100644 --- a/base/util.go +++ b/base/util.go @@ -27,7 +27,7 @@ import ( ) // ConfigPath 配置文件路径 -const ConfigPath = ".ucloud" +var ConfigPath = fmt.Sprintf(".%s", BrandNameLower) // GAP 表格列直接的间隔字符数 const GAP = 2 diff --git a/cmd/api.go b/cmd/api.go index 10441ad347..2162f9710b 100644 --- a/cmd/api.go +++ b/cmd/api.go @@ -35,7 +35,7 @@ const RepeatsField = "repeats" const ConcurrentField = "concurrent" const DefaultConcurrent = 20 const HelpField = "help" -const HelpInfo = `Usage: ucloud api [options] --Action actionName --param1 value1 --param2 value2 ... +const HelpInfo = `Usage: %s api [options] --Action actionName --param1 value1 --param2 value2 ... Options: --local-file string the path of the local file which contains the api parameters --repeats string the number of repeats @@ -50,7 +50,7 @@ func NewCmdAPI(out io.Writer) *cobra.Command { Long: "Call API", Run: func(c *cobra.Command, args []string) { if containHelp(args) { - fmt.Fprintln(out, HelpInfo) + fmt.Fprintln(out, fmt.Sprintf(HelpInfo, base.BrandNameLower)) return } params, err := parseParamsFromCmdLine(args) diff --git a/cmd/backup.go b/cmd/backup.go index 6c7d4396fc..f1ee44f63f 100644 --- a/cmd/backup.go +++ b/cmd/backup.go @@ -197,7 +197,7 @@ func NewCmdUDBBackupDelete(out io.Writer) *cobra.Command { Use: "delete", Short: "Delete backups of MySQL instance", Long: "Delete backups of MySQL instance", - Example: "ucloud udb backup delete --backup-id 65534,65535", + Example: fmt.Sprintf("%s udb backup delete --backup-id 65534,65535", base.BrandNameLower), Run: func(c *cobra.Command, args []string) { for _, id := range ids { req.BackupId = sdk.Int(id) @@ -280,7 +280,7 @@ func NewCmdUDBLogArchiveCreate(out io.Writer) *cobra.Command { Use: "archive", Short: "Archive the log of mysql as a compressed file", Long: "Archive the log of mysql as a compressed file", - Example: "ucloud mysql logs archive --name test.cli2 --udb-id udb-xxx/test.cli1 --log-type slow_query --begin-time 2019-02-23/15:30:00 --end-time 2019-02-24/15:31:00", + Example: fmt.Sprintf("%s mysql logs archive --name test.cli2 --udb-id udb-xxx/test.cli1 --log-type slow_query --begin-time 2019-02-23/15:30:00 --end-time 2019-02-24/15:31:00", base.BrandNameLower), Run: func(c *cobra.Command, args []string) { udbID = base.PickResourceID(udbID) if logType == "slow_query" { @@ -463,7 +463,7 @@ func NewCmdUDBLogArchiveGetDownloadURL(out io.Writer) *cobra.Command { Use: "download", Short: "Display url of an archive(log file)", Long: "Display url of an archive(log file)", - Example: "ucloud mysql logs download --udb-id udb-urixxx/test.cli1 --archive-id 35044", + Example: fmt.Sprintf("%s mysql logs download --udb-id udb-urixxx/test.cli1 --archive-id 35044", base.BrandNameLower), Run: func(c *cobra.Command, args []string) { *req.DBId = base.PickResourceID(*req.DBId) resp, err := base.BizClient.DescribeUDBBinlogBackupURL(req) @@ -501,7 +501,7 @@ func NewCmdUDBLogArchiveDelete(out io.Writer) *cobra.Command { Use: "delete", Short: "Delete log archives(log files)", Long: "Delete log archives(log files)", - Example: "ucloud mysql logs delete --archive-id 35025", + Example: fmt.Sprintf("%s mysql logs delete --archive-id 35025", base.BrandNameLower), Run: func(c *cobra.Command, args []string) { for _, id := range ids { req.BackupId = sdk.Int(id) diff --git a/cmd/bandwidth.go b/cmd/bandwidth.go index 703d2c1243..1b32887831 100644 --- a/cmd/bandwidth.go +++ b/cmd/bandwidth.go @@ -267,7 +267,7 @@ func NewCmdBandwidthPkgCreate() *cobra.Command { Use: "create", Short: "Create bandwidth package", Long: "Create bandwidth package", - Example: "ucloud bw pkg create --eip-id eip-xxx --bandwidth-mb 20 --start-time 2018-12-15/09:20:00 --end-time 2018-12-16/09:20:00", + Example: fmt.Sprintf("%s bw pkg create --eip-id eip-xxx --bandwidth-mb 20 --start-time 2018-12-15/09:20:00 --end-time 2018-12-16/09:20:00", base.BrandNameLower), Run: func(c *cobra.Command, args []string) { st, err := time.ParseInLocation(timeLayout, *start, loc) if err != nil { @@ -381,7 +381,7 @@ func NewCmdBandwidthPkgDelete() *cobra.Command { Use: "delete", Short: "Delete bandwidth packages", Long: "Delete bandwidth packages", - Example: "ucloud bw pkg delete --resource-id bwpack-xxx", + Example: fmt.Sprintf("%s bw pkg delete --resource-id bwpack-xxx", base.BrandNameLower), Run: func(c *cobra.Command, args []string) { for _, id := range ids { id := base.PickResourceID(id) diff --git a/cmd/completion.go b/cmd/completion.go index 969e070c82..7d91beb289 100644 --- a/cmd/completion.go +++ b/cmd/completion.go @@ -54,18 +54,18 @@ func NewCmdCompletion() *cobra.Command { func bashCompletion(cmd *cobra.Command) { platform := runtime.GOOS if platform == "darwin" { - fmt.Println(`Please append 'complete -C $(which ucloud) ucloud' to file '~/.bash_profile'`) + fmt.Printf(`Please append 'complete -C $(which %s) %s' to file '~/.bash_profile'`, base.BrandNameLower, base.BrandNameLower) } else if platform == "linux" { - fmt.Println(`Please append 'complete -C $(which ucloud) ucloud' to file '~/.bashrc'`) + fmt.Printf(`Please append 'complete -C $(which %s) %s' to file '~/.bashrc'`, base.BrandNameLower, base.BrandNameLower) } } func zshCompletion(cmd *cobra.Command) { - fmt.Println(`Please append the following scripts to file '~/.zshrc'. + fmt.Printf(`Please append the following scripts to file '~/.zshrc'. autoload -U +X bashcompinit && bashcompinit -complete -F $(which ucloud) ucloud`) +complete -F $(which %s) %s`, base.BrandNameLower, base.BrandNameLower) } func getBashVersion() (version string, err error) { diff --git a/cmd/configure.go b/cmd/configure.go index fdc5682ed0..c9fff85779 100644 --- a/cmd/configure.go +++ b/cmd/configure.go @@ -37,15 +37,15 @@ const helloUcloud = ` | | | | __/ | | (_) | | |_| | \__/\ | (_) | |_| | (_| | \_| |_/\___|_|_|\___/ \___/ \____/_|\___/ \__,_|\__,_| -If you want add or modify your configurations, run 'ucloud config add/update' +If you want add or modify your configurations, run '%s config add/update' ` // NewCmdInit ucloud init func NewCmdInit() *cobra.Command { cmd := &cobra.Command{ Use: "init", - Short: "Initialize UCloud CLI options", - Long: `Initialize UCloud CLI options such as private-key,public-key,default region,zone and project.`, + Short: fmt.Sprintf("Initialize %s CLI options", base.BrandName), + Long: fmt.Sprintf(`Initialize %s CLI options such as private-key,public-key,default region,zone and project.`, base.BrandName), Run: func(cmd *cobra.Command, args []string) { if base.ConfigIns.PrivateKey != "" && base.ConfigIns.PublicKey != "" { printHello() @@ -90,7 +90,7 @@ func NewCmdInit() *cobra.Command { fmt.Printf("Configured default base url:%s\n", base.ConfigIns.BaseURL) fmt.Printf("Configured default timeout_sec:%ds\n", base.ConfigIns.Timeout) fmt.Printf("Active profile name:%s\n", base.ConfigIns.Profile) - fmt.Println("You can change the default settings by running 'ucloud config update'") + fmt.Printf("You can change the default settings by running '%s config update'\n", base.BrandNameLower) base.ConfigIns.ConfigUploadLog() err = base.AggConfigListIns.Append(base.ConfigIns) if err != nil { @@ -113,9 +113,10 @@ func printHello() { base.Cxt.Printf("You are logged in as: [%s]\n", userInfo.UserEmail) certified := isUserCertified(userInfo) if !certified { - base.Cxt.Println("\nWarning: Please authenticate the account with your valid documentation at 'https://accountv2.ucloud.cn/authentication'.") + authURL := fmt.Sprintf("%s", base.BrandAuthURL) + base.Cxt.Println(fmt.Sprintf("\nWarning: Please authenticate the account with your valid documentation at '%s'.", authURL)) } - base.Cxt.Println(helloUcloud) + base.Cxt.Println(fmt.Sprintf(helloUcloud, base.BrandNameLower)) } // 根据用户设置的region和zone,检查其合法性,补上缺失的部分,给出一个合理的符合用户本意设置的region和zone @@ -139,7 +140,7 @@ func getReasonableRegionZone(cfg *base.AggConfig) (string, string, error) { zones, ok := regionIns.Labels[userRegion] if !ok { - return "", "", fmt.Errorf("region[%s] is not exist! See 'ucloud region'", userRegion) + return "", "", fmt.Errorf("region[%s] is not exist! See '%s region'", userRegion, base.BrandNameLower) } if userZone != "" { @@ -150,7 +151,7 @@ func getReasonableRegionZone(cfg *base.AggConfig) (string, string, error) { } } if !zoneExist { - return "", "", fmt.Errorf("zone[%s] not exist in region[%s]! See 'ucloud config list' and 'ucloud region'", userZone, userRegion) + return "", "", fmt.Errorf("zone[%s] not exist in region[%s]! See '%s config list' and '%s region'", userZone, userRegion, base.BrandNameLower, base.BrandNameLower) } } else if len(zones) > 0 { userZone = zones[0] @@ -167,7 +168,7 @@ func NewCmdConfig() *cobra.Command { Use: "config", Short: "add or update configurations", Long: `add or update configurations, such as private-key, public-key, default region and zone, base-url, timeout-sec, and default project-id`, - Example: "ucloud config --profile=test --region cn-bj2 --active true", + Example: fmt.Sprintf("%s config --profile=test --region cn-bj2 --active true", base.BrandNameLower), Run: func(c *cobra.Command, args []string) { if cfg.Profile == "" { c.HelpFunc()(c, args) @@ -303,14 +304,14 @@ func NewCmdConfig() *cobra.Command { flags.StringVar(&cfg.Profile, "profile", "", "Required. Set name of CLI profile") flags.StringVar(&cfg.PublicKey, "public-key", "", "Optional. Set public key") flags.StringVar(&cfg.PrivateKey, "private-key", "", "Optional. Set private key") - flags.StringVar(&cfg.Region, "region", "", "Optional. Set default region. For instance 'cn-bj2' See 'ucloud region'") - flags.StringVar(&cfg.Zone, "zone", "", "Optional. Set default zone. For instance 'cn-bj2-02'. See 'ucloud region'") - flags.StringVar(&cfg.ProjectID, "project-id", "", "Optional. Set default project. For instance 'org-xxxxxx'. See 'ucloud project list") - flags.StringVar(&cfg.BaseURL, "base-url", "", "Optional. Set default base url. For instance 'https://api.ucloud.cn/'") + flags.StringVar(&cfg.Region, "region", "", fmt.Sprintf("Optional. Set default region. For instance 'cn-bj2' See '%s region'", base.BrandNameLower)) + flags.StringVar(&cfg.Zone, "zone", "", fmt.Sprintf("Optional. Set default zone. For instance 'cn-bj2-02'. See '%s region'", base.BrandNameLower)) + flags.StringVar(&cfg.ProjectID, "project-id", "", fmt.Sprintf("Optional. Set default project. For instance 'org-xxxxxx'. See '%s project list'", base.BrandNameLower)) + flags.StringVar(&cfg.BaseURL, "base-url", "", fmt.Sprintf("Optional. Set default base url. For instance '%s'", base.BrandAPIURL)) flags.IntVar(&cfg.Timeout, "timeout-sec", 0, "Optional. Set default timeout for requesting API. Unit: seconds") cfg.MaxRetryTimes = flags.Int("max-retry-times", 0, "Optional. Set default max-retry-times for idempotent APIs which can be called many times without side effect, for example 'ReleaseEIP'") flags.StringVar(&active, "active", "", "Optional. Mark the profile to be effective or not. Accept valeus: true or false") - flags.StringVar(&upload, "agree-upload-log", "false", "Optional. Agree to upload log in local file ~/.ucloud/cli.log or not. Accept valeus: true or false") + flags.StringVar(&upload, "agree-upload-log", "false", fmt.Sprintf("Optional. Agree to upload log in local file ~/%s/cli.log or not. Accept valeus: true or false", base.ConfigPath)) flags.SetFlagValues("active", "true", "false") flags.SetFlagValues("agree-upload-log", "true", "false") @@ -384,14 +385,14 @@ func NewCmdConfigAdd() *cobra.Command { flags.StringVar(&cfg.Profile, "profile", "", "Required. Set name of CLI profile") flags.StringVar(&cfg.PublicKey, "public-key", "", "Required. Set public key") flags.StringVar(&cfg.PrivateKey, "private-key", "", "Required. Set private key") - flags.StringVar(&cfg.Region, "region", "", "Optional. Set default region. For instance 'cn-bj2' See 'ucloud region'") - flags.StringVar(&cfg.Zone, "zone", "", "Optional. Set default zone. For instance 'cn-bj2-02'. See 'ucloud region'") - flags.StringVar(&cfg.ProjectID, "project-id", "", "Optional. Set default project. For instance 'org-xxxxxx'. See 'ucloud project list") - flags.StringVar(&cfg.BaseURL, "base-url", base.DefaultBaseURL, "Optional. Set default base url. For instance 'https://api.ucloud.cn/'") + flags.StringVar(&cfg.Region, "region", "", fmt.Sprintf("Optional. Set default region. For instance 'cn-bj2' See '%s region'", base.BrandNameLower)) + flags.StringVar(&cfg.Zone, "zone", "", fmt.Sprintf("Optional. Set default zone. For instance 'cn-bj2-02'. See '%s region'", base.BrandNameLower)) + flags.StringVar(&cfg.ProjectID, "project-id", "", fmt.Sprintf("Optional. Set default project. For instance 'org-xxxxxx'. See '%s project list'", base.BrandNameLower)) + flags.StringVar(&cfg.BaseURL, "base-url", base.DefaultBaseURL, fmt.Sprintf("Optional. Set default base url. For instance '%s'", base.BrandAPIURL)) flags.IntVar(&cfg.Timeout, "timeout-sec", base.DefaultTimeoutSec, "Optional. Set default timeout for requesting API. Unit: seconds") cfg.MaxRetryTimes = flags.Int("max-retry-times", base.DefaultMaxRetryTimes, "Optional. Set default max-retry-times for idempotent APIs which can be called many times without side effect, for example 'ReleaseEIP'") flags.StringVar(&active, "active", "false", "Optional. Mark the profile to be effective or not. Accept valeus: true or false") - flags.StringVar(&upload, "agree-upload-log", "false", "Optional. Agree to upload log in local file ~/.ucloud/cli.log or not. Accept valeus: true or false") + flags.StringVar(&upload, "agree-upload-log", "false", fmt.Sprintf("Optional. Agree to upload log in local file ~/%s/cli.log or not. Accept valeus: true or false", base.ConfigPath)) flags.SetFlagValues("active", "true", "false") flags.SetFlagValues("agree-upload-log", "true", "false") @@ -520,14 +521,14 @@ func NewCmdConfigUpdate() *cobra.Command { flags.StringVar(&cfg.Profile, "profile", "", "Required. Set name of CLI profile") flags.StringVar(&cfg.PublicKey, "public-key", "", "Required. Set public key") flags.StringVar(&cfg.PrivateKey, "private-key", "", "Required. Set private key") - flags.StringVar(&cfg.Region, "region", "", "Optional. Set default region. For instance 'cn-bj2' See 'ucloud region'") - flags.StringVar(&cfg.Zone, "zone", "", "Optional. Set default zone. For instance 'cn-bj2-02'. See 'ucloud region'") - flags.StringVar(&cfg.ProjectID, "project-id", "", "Optional. Set default project. For instance 'org-xxxxxx'. See 'ucloud project list") - flags.StringVar(&cfg.BaseURL, "base-url", "", "Optional. Set default base url. For instance 'https://api.ucloud.cn/'") + flags.StringVar(&cfg.Region, "region", "", fmt.Sprintf("Optional. Set default region. For instance 'cn-bj2' See '%s region'", base.BrandNameLower)) + flags.StringVar(&cfg.Zone, "zone", "", fmt.Sprintf("Optional. Set default zone. For instance 'cn-bj2-02'. See '%s region'", base.BrandNameLower)) + flags.StringVar(&cfg.ProjectID, "project-id", "", fmt.Sprintf("Optional. Set default project. For instance 'org-xxxxxx'. See '%s project list'", base.BrandNameLower)) + flags.StringVar(&cfg.BaseURL, "base-url", "", fmt.Sprintf("Optional. Set default base url. For instance '%s'", base.BrandAPIURL)) flags.StringVar(&timeout, "timeout-sec", "", "Optional. Set default timeout for requesting API. Unit: seconds") flags.StringVar(&maxRetries, "max-retry-times", "", "Optional. Set default max retry times for idempotent APIs which can be called many times without side effect, for example 'ReleaseEIP'") flags.StringVar(&active, "active", "", "Optional. Mark the profile to be effective") - flags.StringVar(&upload, "agree-upload-log", "", "Optional. Agree to upload log in local file ~/.ucloud/cli.log or not. Accept valeus: true or false") + flags.StringVar(&upload, "agree-upload-log", "", fmt.Sprintf("Optional. Agree to upload log in local file ~/%s/cli.log or not. Accept valeus: true or false", base.ConfigPath)) flags.SetFlagValuesFunc("profile", func() []string { return base.AggConfigListIns.GetProfileNameList() }) flags.SetFlagValuesFunc("region", getRegionList) @@ -563,7 +564,7 @@ func NewCmdConfigDelete() *cobra.Command { Use: "delete", Short: "delete configurations by profile name", Long: "delete configurations by profile name", - Example: "ucloud config delete --profile test", + Example: fmt.Sprintf("%s config delete --profile test", base.BrandNameLower), Run: func(c *cobra.Command, args []string) { profiles := base.AggConfigListIns.GetProfileNameList() allProfileMap := make(map[string]bool) diff --git a/cmd/disk.go b/cmd/disk.go index 4f901616f3..d97b96da8c 100644 --- a/cmd/disk.go +++ b/cmd/disk.go @@ -20,15 +20,15 @@ import ( "strings" "github.com/spf13/cobra" + "github.com/ucloud/ucloud-cli/base" + "github.com/ucloud/ucloud-cli/ux" "github.com/ucloud/ucloud-sdk-go/ucloud/request" "github.com/ucloud/ucloud-sdk-go/private/services/uhost" "github.com/ucloud/ucloud-sdk-go/services/udisk" sdk "github.com/ucloud/ucloud-sdk-go/ucloud" - "github.com/ucloud/ucloud-cli/base" "github.com/ucloud/ucloud-cli/model/status" - "github.com/ucloud/ucloud-cli/ux" ) // NewCmdDisk ucloud disk @@ -249,7 +249,7 @@ func NewCmdDiskAttach(out io.Writer) *cobra.Command { Use: "attach", Short: "Attach udisk instances to an uhost", Long: "Attach udisk instances to an uhost", - Example: "ucloud udisk attach --uhost-id uhost-xxxx --udisk-id bs-xxx1,bs-xxx2", + Example: fmt.Sprintf("%s udisk attach --uhost-id uhost-xxxx --udisk-id bs-xxx1,bs-xxx2", base.BrandNameLower), Run: func(cmd *cobra.Command, args []string) { for _, id := range *udiskIDs { id = base.PickResourceID(id) @@ -302,7 +302,8 @@ func NewCmdDiskDetach(out io.Writer) *cobra.Command { Short: "Detach udisk instances from an uhost", Long: "Detach udisk instances from an uhost", Run: func(cmd *cobra.Command, args []string) { - text := `Please confirm that you have already unmounted file system corresponding to this hard drive,(See "https://docs.ucloud.cn/storage_cdn/udisk/userguide/umount" for help), otherwise it will cause file system damage and UHost cannot be normally shut down. Sure to detach?` + docURL := fmt.Sprintf("%s", base.BrandUmountURL) + text := fmt.Sprintf(`Please confirm that you have already unmounted file system corresponding to this hard drive,(See "%s" for help), otherwise it will cause file system damage and UHost cannot be normally shut down. Sure to detach?`, docURL) if !*yes { sure, err := ux.Prompt(text) if err != nil { @@ -465,7 +466,8 @@ func NewCmdDiskClone(out io.Writer) *cobra.Command { req.ChargeType = flags.String("charge-type", "Month", "Optional.'Year',pay yearly;'Month',pay monthly;'Dynamic', pay hourly") req.Quantity = flags.Int("quantity", 1, "Optional. The duration of the instance. N years/months.") enableDataArk = flags.String("enable-data-ark", "false", "Optional. DataArk supports real-time backup, which can restore the udisk back to any moment within the last 12 hours.") - req.CouponId = flags.String("coupon-id", "", "Optional. Coupon ID, The Coupon can deduct part of the payment,see https://accountv2.ucloud.cn") + couponURL := fmt.Sprintf("%s", base.BrandAccountURL) + req.CouponId = flags.String("coupon-id", "", fmt.Sprintf("Optional. Coupon ID, The Coupon can deduct part of the payment,see %s", couponURL)) async = flags.Bool("async", false, "Optional. Do not wait for the long-running operation to finish.") flags.SetFlagValues("charge-type", "Month", "Year", "Dynamic", "Trial") diff --git a/cmd/eip.go b/cmd/eip.go index 2e45dce86e..ac62beed64 100644 --- a/cmd/eip.go +++ b/cmd/eip.go @@ -73,8 +73,8 @@ func NewCmdEIPList(out io.Writer) *cobra.Command { cmd := &cobra.Command{ Use: "list", Short: "List all EIP instances", - Long: `List all EIP instances`, - Example: "ucloud eip list", + Long: "List all EIP instances", + Example: fmt.Sprintf("%s eip list", base.BrandNameLower), Run: func(cmd *cobra.Command, args []string) { var eipList []unet.UnetEIPSet if fetchAll || pageOff { @@ -228,7 +228,7 @@ func NewCmdEIPAllocate() *cobra.Command { Use: "allocate", Short: "Allocate EIP", Long: "Allocate EIP", - Example: "ucloud eip allocate --line BGP --bandwidth-mb 2", + Example: fmt.Sprintf("%s eip allocate --line BGP --bandwidth-mb 2", base.BrandNameLower), Run: func(cmd *cobra.Command, args []string) { if *req.OperatorName == "" { *req.OperatorName = getEIPLine(*req.Region) @@ -277,7 +277,7 @@ func NewCmdEIPBind() *cobra.Command { Use: "bind", Short: "Bind EIP with uhost", Long: "Bind EIP with uhost", - Example: "ucloud eip bind --eip-id eip-xxx --resource-id uhost-xxx", + Example: fmt.Sprintf("%s eip bind --eip-id eip-xxx --resource-id uhost-xxx", base.BrandNameLower), Run: func(cmd *cobra.Command, args []string) { for _, eipID := range eipIDs { bindEIP(resourceID, resourceType, &eipID, projectID, region) @@ -363,7 +363,7 @@ func NewCmdEIPUnbind() *cobra.Command { Use: "unbind", Short: "Unbind EIP with uhost", Long: "Unbind EIP with uhost", - Example: "ucloud eip unbind --eip-id eip-xxx", + Example: fmt.Sprintf("%s eip unbind --eip-id eip-xxx", base.BrandNameLower), Run: func(cmd *cobra.Command, args []string) { req.ProjectId = sdk.String(base.PickResourceID(*req.ProjectId)) for _, eip := range eipIDs { @@ -435,7 +435,7 @@ func NewCmdEIPRelease() *cobra.Command { Use: "release", Short: "Release EIP", Long: "Release EIP", - Example: "ucloud eip release --eip-id eip-xx1,eip-xx2", + Example: fmt.Sprintf("%s eip release --eip-id eip-xx1,eip-xx2", base.BrandNameLower), Run: func(cmd *cobra.Command, args []string) { req.ProjectId = sdk.String(base.PickResourceID(*req.ProjectId)) for _, id := range ids { @@ -470,8 +470,8 @@ func NewCmdEIPModifyBandwidth() *cobra.Command { Use: "modify-bw", Short: "Modify bandwith of EIP instances", Long: "Modify bandwith of EIP instances", - Example: "ucloud eip modify-bw --eip-id eip-xx1,eip-xx2 --bandwidth-mb 20", - // Deprecated: "use 'ucloud eip modiy'", + Example: fmt.Sprintf("%s eip modify-bw --eip-id eip-xx1,eip-xx2 --bandwidth-mb 20", base.BrandNameLower), + // Deprecated: fmt.Sprintf("use '%s eip modiy'", base.BrandNameLower), Run: func(cmd *cobra.Command, args []string) { for _, id := range ids { id = base.PickResourceID(id) @@ -506,7 +506,7 @@ func NewCmdEIPSetChargeMode() *cobra.Command { Use: "modify-traffic-mode", Short: "Modify charge mode of EIP instances", Long: "Modify charge mode of EIP instances", - Example: "ucloud eip modify-traffic-mode --eip-id eip-xx1,eip-xx2 --traffic-mode Traffic", + Example: fmt.Sprintf("%s eip modify-traffic-mode --eip-id eip-xx1,eip-xx2 --traffic-mode Traffic", base.BrandNameLower), Run: func(cmd *cobra.Command, args []string) { for _, id := range ids { id = base.PickResourceID(id) @@ -549,7 +549,7 @@ func NewCmdEIPJoinSharedBW() *cobra.Command { Use: "join-shared-bw", Short: "Join shared bandwidth", Long: "Join shared bandwidth", - Example: "ucloud eip join-shared-bw --eip-id eip-xxx --shared-bw-id bwshare-xxx", + Example: fmt.Sprintf("%s eip join-shared-bw --eip-id eip-xxx --shared-bw-id bwshare-xxx", base.BrandNameLower), Run: func(c *cobra.Command, args []string) { for _, eip := range eipIDs { req.EIPIds = append(req.EIPIds, base.PickResourceID(eip)) @@ -567,8 +567,8 @@ func NewCmdEIPJoinSharedBW() *cobra.Command { flags.SortFlags = false flags.StringSliceVar(&eipIDs, "eip-id", nil, "Required. Resource ID of EIPs to join shared bandwdith") req.ShareBandwidthId = flags.String("shared-bw-id", "", "Required. Resource ID of shared bandwidth to be joined") - req.Region = flags.String("region", base.ConfigIns.Region, "Optional. Region, see 'ucloud region'") - req.ProjectId = flags.String("project-id", base.ConfigIns.ProjectID, "Optional. Project-id, see 'ucloud project list'") + req.Region = flags.String("region", base.ConfigIns.Region, fmt.Sprintf("Optional. Region, see '%s region'", base.BrandNameLower)) + req.ProjectId = flags.String("project-id", base.ConfigIns.ProjectID, fmt.Sprintf("Optional. Project-id, see '%s project list'", base.BrandNameLower)) flags.SetFlagValuesFunc("eip-id", func() []string { return getAllEip(*req.ProjectId, *req.Region, nil, []string{status.EIP_CHARGE_BANDWIDTH, status.EIP_CHARGE_TRAFFIC}) }) @@ -590,7 +590,7 @@ func NewCmdEIPLeaveSharedBW() *cobra.Command { Use: "leave-shared-bw", Short: "Leave shared bandwidth", Long: "Leave shared bandwidth", - Example: "ucloud eip leave-shared-bw --eip-id eip-b2gvu3", + Example: fmt.Sprintf("%s eip leave-shared-bw --eip-id eip-b2gvu3", base.BrandNameLower), Run: func(c *cobra.Command, args []string) { if *req.ShareBandwidthId == "" { for _, eipID := range eipIDs { @@ -633,8 +633,8 @@ func NewCmdEIPLeaveSharedBW() *cobra.Command { req.Bandwidth = flags.Int("bandwidth-mb", 1, "Required. Bandwidth of EIP after leaving shared bandwidth, ranging [1,300] for 'Traffic' charge mode, ranging [1,800] for 'Bandwidth' charge mode. Unit:Mb") req.PayMode = flags.String("traffic-mode", "Bandwidth", "Optional. Charge mode of the EIP after leaving shared bandwidth, 'Bandwidth' or 'Traffic'") req.ShareBandwidthId = flags.String("shared-bw-id", "", "Optional. Resource ID of shared bandwidth instance, assign this flag to make the operation faster") - req.Region = flags.String("region", base.ConfigIns.Region, "Optional. Region, see 'ucloud region'") - req.ProjectId = flags.String("project-id", base.ConfigIns.ProjectID, "Optional. Project-id, see 'ucloud project list'") + req.Region = flags.String("region", base.ConfigIns.Region, fmt.Sprintf("Optional. Region, see '%s region'", base.BrandNameLower)) + req.ProjectId = flags.String("project-id", base.ConfigIns.ProjectID, fmt.Sprintf("Optional. Project-id, see '%s project list'", base.BrandNameLower)) flags.SetFlagValues("traffic-mode", "Bandwidth", "Traffic") flags.SetFlagValuesFunc("eip-id", func() []string { diff --git a/cmd/ext.go b/cmd/ext.go index d50850ec3c..daaa460d29 100644 --- a/cmd/ext.go +++ b/cmd/ext.go @@ -30,8 +30,8 @@ import ( func NewCmdExt() *cobra.Command { cmd := &cobra.Command{ Use: "ext", - Short: "extended commands of UCloud CLI", - Long: "extended commands of UCloud CLI", + Short: fmt.Sprintf("extended commands of %s CLI", base.BrandName), + Long: fmt.Sprintf("extended commands of %s CLI", base.BrandName), } cmd.AddCommand(NewCmdExtUHost()) return cmd @@ -59,7 +59,7 @@ func NewCmdExtUHostSwitchEIP() *cobra.Command { Use: "switch-eip", Short: "Switch EIP for UHost instances", Long: "Switch EIP for UHost instances", - Example: "ucloud ext uhost switch-eip --uhost-id uhost-1n1sxx2,uhost-li4jxx1 --create-eip-bandwidth-mb 2", + Example: fmt.Sprintf("%s ext uhost switch-eip --uhost-id uhost-1n1sxx2,uhost-li4jxx1 --create-eip-bandwidth-mb 2", base.BrandNameLower), Run: func(c *cobra.Command, args []string) { project = base.PickResourceID(project) eipAddrMap := make(map[string]bool) diff --git a/cmd/firewall.go b/cmd/firewall.go index a1f8deb57f..83c1fbf20f 100644 --- a/cmd/firewall.go +++ b/cmd/firewall.go @@ -98,8 +98,8 @@ func NewCmdFirewallList(out io.Writer) *cobra.Command { } flags := cmd.Flags() flags.SortFlags = false - req.Region = flags.String("region", base.ConfigIns.Region, "Optional. Region, see 'ucloud region'") - req.ProjectId = flags.String("project-id", base.ConfigIns.ProjectID, "Optional. Project-id, see 'ucloud project list'") + req.Region = flags.String("region", base.ConfigIns.Region, fmt.Sprintf("Optional. Region, see '%s region'", base.BrandNameLower)) + req.ProjectId = flags.String("project-id", base.ConfigIns.ProjectID, fmt.Sprintf("Optional. Project-id, see '%s project list'", base.BrandNameLower)) req.FWId = flags.String("firewall-id", "", "Optional. The Rsource ID of firewall. Return all firewalls by default.") req.ResourceType = flags.String("bound-resource-type", "", "Optional. The type of resource bound on the firewall") req.ResourceId = flags.String("bound-resource-id", "", "Optional. The resource ID of resource bound on the firewall") @@ -160,11 +160,11 @@ func NewCmdFirewallCreate(out io.Writer) *cobra.Command { } flags := cmd.Flags() flags.SortFlags = false - flags.StringSliceVar(&rules, "rules", nil, "Required if rules-file doesn't exist. Schema: Protocol|Port|IP|Action|Level. Prototol range 'TCP','UDP','ICMP' and 'GRE'; Port is a local port accessed by source address, port range [0-65535]; IP is the source address of the network packet that requests ucloud host resource, supporting IP address and network segment, such as '120.132.69.216' or '0.0.0.0/0'; Action is the processing behavior of the packet when the firewall is in effect, including 'ACCEPT' AND 'DROP'; Level, when a rule is added to a firewall, the rules take effect in order of level, which range 'HIGH','MEDIUM' and 'LOW'. For example, 'TCP|22|192.168.1.1/22|DROP|LOW'") + flags.StringSliceVar(&rules, "rules", nil, fmt.Sprintf("Required if rules-file doesn't exist. Schema: Protocol|Port|IP|Action|Level. Prototol range 'TCP','UDP','ICMP' and 'GRE'; Port is a local port accessed by source address, port range [0-65535]; IP is the source address of the network packet that requests %s host resource, supporting IP address and network segment, such as '120.132.69.216' or '0.0.0.0/0'; Action is the processing behavior of the packet when the firewall is in effect, including 'ACCEPT' AND 'DROP'; Level, when a rule is added to a firewall, the rules take effect in order of level, which range 'HIGH','MEDIUM' and 'LOW'. For example, 'TCP|22|192.168.1.1/22|DROP|LOW'", base.BrandNameLower)) flags.StringVar(&rulesFilePath, "rules-file", "", "Required if rules doesn't exist. Path of rules file, in which each rule occupies one line. Schema: Protocol|Port|IP|Action|Level.") req.Name = flags.String("name", "", "Required. Name of firewall to create") - req.Region = flags.String("region", base.ConfigIns.Region, "Optional. Region, see 'ucloud region'") - req.ProjectId = flags.String("project-id", base.ConfigIns.ProjectID, "Optional. Project-id, see 'ucloud project list'") + req.Region = flags.String("region", base.ConfigIns.Region, fmt.Sprintf("Optional. Region, see '%s region'", base.BrandNameLower)) + req.ProjectId = flags.String("project-id", base.ConfigIns.ProjectID, fmt.Sprintf("Optional. Project-id, see '%s project list'", base.BrandNameLower)) req.Tag = flags.String("group", "", "Optional. Group of the firewall to create") req.Remark = flags.String("remark", "", "Optional. Remark of the firewall to create") cmd.MarkFlagRequired("name") @@ -231,10 +231,10 @@ func NewCmdFirewallAddRule(out io.Writer) *cobra.Command { flags.SortFlags = false flags.StringSliceVar(&fwIDs, "fw-id", nil, "Required. Resource ID of firewalls to update") - flags.StringSliceVar(&req.Rule, "rules", nil, "Required if rules-file is empay. Rules to add to firewall. Schema:'Protocol|Port|IP|Action|Level'. See 'ucloud firewall create --help' for detail.") + flags.StringSliceVar(&req.Rule, "rules", nil, fmt.Sprintf("Required if rules-file is empay. Rules to add to firewall. Schema:'Protocol|Port|IP|Action|Level'. See '%s firewall create --help' for detail.", base.BrandNameLower)) flags.StringVar(&rulesFilePath, "rules-file", "", "Required if rules is empty. Path of rules file, in which each rule occupies one line. Schema: Protocol|Port|IP|Action|Level.") - req.Region = flags.String("region", base.ConfigIns.Region, "Optional. Region, see 'ucloud region'") - req.ProjectId = flags.String("project-id", base.ConfigIns.ProjectID, "Optional. Project-id, see 'ucloud project list'") + req.Region = flags.String("region", base.ConfigIns.Region, fmt.Sprintf("Optional. Region, see '%s region'", base.BrandNameLower)) + req.ProjectId = flags.String("project-id", base.ConfigIns.ProjectID, fmt.Sprintf("Optional. Project-id, see '%s project list'", base.BrandNameLower)) flags.SetFlagValuesFunc("fw-id", func() []string { return getFirewallIDNames(*req.ProjectId, *req.Region) @@ -308,10 +308,10 @@ func NewCmdFirewallDeleteRule(out io.Writer) *cobra.Command { flags.SortFlags = false flags.StringSliceVar(&fwIDs, "fw-id", nil, "Required. Resource ID of firewalls to update") - flags.StringSliceVar(&req.Rule, "rules", nil, "Required if rules-file is empay. Rules to add to firewall. Schema:'Protocol|Port|IP|Action|Level'. See 'ucloud firewall create --help' for detail.") + flags.StringSliceVar(&req.Rule, "rules", nil, fmt.Sprintf("Required if rules-file is empay. Rules to add to firewall. Schema:'Protocol|Port|IP|Action|Level'. See '%s firewall create --help' for detail.", base.BrandNameLower)) flags.StringVar(&rulesFilePath, "rules-file", "", "Required if rules is empty. Path of rules file, in which each rule occupies one line. Schema: Protocol|Port|IP|Action|Level.") - req.Region = flags.String("region", base.ConfigIns.Region, "Optional. Region, see 'ucloud region'") - req.ProjectId = flags.String("project-id", base.ConfigIns.ProjectID, "Optional. Project-id, see 'ucloud project list'") + req.Region = flags.String("region", base.ConfigIns.Region, fmt.Sprintf("Optional. Region, see '%s region'", base.BrandNameLower)) + req.ProjectId = flags.String("project-id", base.ConfigIns.ProjectID, fmt.Sprintf("Optional. Project-id, see '%s project list'", base.BrandNameLower)) flags.SetFlagValuesFunc("fw-id", func() []string { return getFirewallIDNames(*req.ProjectId, *req.Region) @@ -328,9 +328,9 @@ func NewCmdFirewallApply() *cobra.Command { fwID := "" cmd := &cobra.Command{ Use: "apply", - Short: "Applay firewall to ucloud service", - Long: "Applay firewall to ucloud service", - Example: "ucloud firewall apply --fw-id firewall-xxx --resource-id uhost-xxx --resource-type uhost", + Short: fmt.Sprintf("Applay firewall to %s service", base.BrandNameLower), + Long: fmt.Sprintf("Applay firewall to %s service", base.BrandNameLower), + Example: fmt.Sprintf("%s firewall apply --fw-id firewall-xxx --resource-id uhost-xxx --resource-type uhost", base.BrandNameLower), Run: func(c *cobra.Command, args []string) { req.FWId = sdk.String(base.PickResourceID(fwID)) for _, id := range resourceIDs { @@ -347,11 +347,11 @@ func NewCmdFirewallApply() *cobra.Command { flags := cmd.Flags() flags.SortFlags = false - flags.StringVar(&fwID, "fw-id", "", "Required. Resource ID of firewall to apply to some ucloud resource") + flags.StringVar(&fwID, "fw-id", "", fmt.Sprintf("Required. Resource ID of firewall to apply to some %s resource", base.BrandNameLower)) req.ResourceType = flags.String("resource-type", "", "Required. Resource type of resource to be applied firewall. Range 'uhost','unatgw','upm','hadoophost','fortresshost','udhost','udockhost','dbaudit'.") flags.StringSliceVar(&resourceIDs, "resource-id", nil, "Resource ID of resources to be applied firewall") - req.Region = flags.String("region", base.ConfigIns.Region, "Optional. Region, see 'ucloud region'") - req.ProjectId = flags.String("project-id", base.ConfigIns.ProjectID, "Optional. Project-id, see 'ucloud project list'") + req.Region = flags.String("region", base.ConfigIns.Region, fmt.Sprintf("Optional. Region, see '%s region'", base.BrandNameLower)) + req.ProjectId = flags.String("project-id", base.ConfigIns.ProjectID, fmt.Sprintf("Optional. Project-id, see '%s project list'", base.BrandNameLower)) flags.SetFlagValues("resource-type", "uhost", "unatgw", "upm", "hadoophost", "fortresshost", "udhost", "udockhost", "dbaudit") flags.SetFlagValuesFunc("fw-id", func() []string { @@ -374,7 +374,7 @@ func NewCmdFirewallCopy() *cobra.Command { Use: "copy", Short: "Copy firewall", Long: "Copy firewall", - Example: "ucloud firewall copy --src-fw firewall-xxx --target-region cn-bj2 --name test", + Example: fmt.Sprintf("%s firewall copy --src-fw firewall-xxx --target-region cn-bj2 --name test", base.BrandNameLower), Run: func(c *cobra.Command, args []string) { fwID := base.PickResourceID(srcFirewall) firewall, err := getFirewall(fwID, *req.ProjectId, srcRegion) @@ -403,7 +403,7 @@ func NewCmdFirewallCopy() *cobra.Command { req.Name = flags.String("name", "", "Required. Name of new firewall") flags.StringVar(&srcRegion, "region", base.ConfigIns.Region, "Optional. Current region, used to fetch source firewall") req.Region = flags.String("target-region", base.ConfigIns.Region, "Optional. Copy firewall to target region") - req.ProjectId = flags.String("project-id", base.ConfigIns.ProjectID, "Optional. Project-id, see 'ucloud project list'") + req.ProjectId = flags.String("project-id", base.ConfigIns.ProjectID, fmt.Sprintf("Optional. Project-id, see '%s project list'", base.BrandNameLower)) flags.SetFlagValuesFunc("src-fw", func() []string { return getFirewallIDNames(*req.ProjectId, srcRegion) @@ -423,9 +423,9 @@ func NewCmdFirewallDelete() *cobra.Command { ids := []string{} cmd := &cobra.Command{ Use: "delete", - Short: "Delete firewall by resource ids or names", - Long: "Delete firewall by resource ids or names", - Example: "ucloud firewall delete --fw-id firewall-xxx", + Short: fmt.Sprintf("Delete firewall by resource ids or names"), + Long: fmt.Sprintf("Delete firewall by resource ids or names"), + Example: fmt.Sprintf("%s firewall delete --fw-id firewall-xxx", base.BrandNameLower), Run: func(c *cobra.Command, args []string) { for _, id := range ids { req.FWId = sdk.String(base.PickResourceID(id)) @@ -441,8 +441,8 @@ func NewCmdFirewallDelete() *cobra.Command { flags := cmd.Flags() flags.SortFlags = false flags.StringSliceVar(&ids, "fw-id", nil, "Required. Resource IDs of firewall to delete") - req.Region = flags.String("region", base.ConfigIns.Region, "Optional. Region, see 'ucloud region'") - req.ProjectId = flags.String("project-id", base.ConfigIns.ProjectID, "Optional. Project-id, see 'ucloud project list'") + req.Region = flags.String("region", base.ConfigIns.Region, fmt.Sprintf("Optional. Region, see '%s region'", base.BrandNameLower)) + req.ProjectId = flags.String("project-id", base.ConfigIns.ProjectID, fmt.Sprintf("Optional. Project-id, see '%s project list'", base.BrandNameLower)) cmd.MarkFlagRequired("fw-id") flags.SetFlagValuesFunc("fw-id", func() []string { @@ -495,8 +495,8 @@ func NewCmdFirewallResource(out io.Writer) *cobra.Command { flags.SortFlags = false flags.StringVar(&fwID, "fw-id", "", "Required. Resource ID of firewall") - req.Region = flags.String("region", base.ConfigIns.Region, "Optional. Region, see 'ucloud region'") - req.ProjectId = flags.String("project-id", base.ConfigIns.ProjectID, "Optional. Project-id, see 'ucloud project list'") + req.Region = flags.String("region", base.ConfigIns.Region, fmt.Sprintf("Optional. Region, see '%s region'", base.BrandNameLower)) + req.ProjectId = flags.String("project-id", base.ConfigIns.ProjectID, fmt.Sprintf("Optional. Project-id, see '%s project list'", base.BrandNameLower)) req.Offset = flags.Int("offset", 0, "Optional. Offset") req.Limit = flags.Int("limit", 50, "Optional. Limit") @@ -547,8 +547,8 @@ func NewCmdFirewallUpdate(out io.Writer) *cobra.Command { flags.SortFlags = false flags.StringSliceVar(&fwIDs, "fw-id", nil, "Required. Resource ID of firewalls") - req.Region = flags.String("region", base.ConfigIns.Region, "Optional. Region, see 'ucloud region'") - req.ProjectId = flags.String("project-id", base.ConfigIns.ProjectID, "Optional. Project-id, see 'ucloud project list'") + req.Region = flags.String("region", base.ConfigIns.Region, fmt.Sprintf("Optional. Region, see '%s region'", base.BrandNameLower)) + req.ProjectId = flags.String("project-id", base.ConfigIns.ProjectID, fmt.Sprintf("Optional. Project-id, see '%s project list'", base.BrandNameLower)) req.Name = flags.String("name", "", "Name of firewall") req.Tag = flags.String("group", "", "Group of firewall") req.Remark = flags.String("remark", "", "Remark of firewall") diff --git a/cmd/globalssh.go b/cmd/globalssh.go index 6fcfbdb6f8..7ef3e56d0a 100644 --- a/cmd/globalssh.go +++ b/cmd/globalssh.go @@ -62,8 +62,8 @@ func NewCmdGsshList(out io.Writer) *cobra.Command { cmd := &cobra.Command{ Use: "list", Short: "List all GlobalSSH instances", - Long: `List all GlobalSSH instances`, - Example: "ucloud gssh list", + Long: "List all GlobalSSH instances", + Example: fmt.Sprintf("%s gssh list", base.BrandNameLower), Run: func(cmd *cobra.Command, args []string) { var areaMap = map[string]string{ "洛杉矶": "LosAngeles", @@ -164,7 +164,7 @@ func NewCmdGsshCreate() *cobra.Command { Use: "create", Short: "Create GlobalSSH instance", Long: "Create GlobalSSH instance", - Example: "ucloud gssh create --location Washington --target-ip 8.8.8.8", + Example: fmt.Sprintf("%s gssh create --location Washington --target-ip 8.8.8.8", base.BrandNameLower), Run: func(cmd *cobra.Command, args []string) { port := *req.Port for code, area := range areaCodeMap { @@ -188,7 +188,7 @@ func NewCmdGsshCreate() *cobra.Command { flags := cmd.Flags() flags.SortFlags = false - req.AreaCode = cmd.Flags().String("location", "", "Required. Location of the source server. See 'ucloud gssh location'") + req.AreaCode = cmd.Flags().String("location", "", fmt.Sprintf("Required. Location of the source server. See '%s gssh location'", base.BrandNameLower)) targetIP = cmd.Flags().IP("target-ip", nil, "Required. IP of the source server. Required") bindProjectID(req, flags) req.Port = cmd.Flags().Int("port", 22, "Optional. Port of The SSH service between 1 and 65535. Do not use ports such as 80, 443 or 65123.") @@ -223,7 +223,7 @@ func NewCmdGsshDelete() *cobra.Command { Use: "delete", Short: "Delete GlobalSSH instance", Long: "Delete GlobalSSH instance", - Example: "ucloud gssh delete --gssh-id uga-xx1 --id uga-xx2", + Example: fmt.Sprintf("%s gssh delete --gssh-id uga-xx1 --id uga-xx2", base.BrandNameLower), Run: func(cmd *cobra.Command, args []string) { req.ProjectId = sdk.String(base.PickResourceID(*req.ProjectId)) for _, id := range *gsshIds { @@ -258,7 +258,7 @@ func NewCmdGsshModify() *cobra.Command { Use: "update", Short: "Update GlobalSSH instance", Long: "Update GlobalSSH instance, including port and remark attribute", - Example: "ucloud gssh update --gssh-id uga-xxx --port 22", + Example: fmt.Sprintf("%s gssh update --gssh-id uga-xxx --port 22", base.BrandNameLower), Run: func(cmd *cobra.Command, args []string) { gsshModifyPortReq.ProjectId = sdk.String(project) gsshModifyRemarkReq.ProjectId = sdk.String(project) diff --git a/cmd/image.go b/cmd/image.go index c3ed24925b..f071ae3d2a 100644 --- a/cmd/image.go +++ b/cmd/image.go @@ -65,7 +65,7 @@ func NewCmdUImageList(out io.Writer) *cobra.Command { Use: "list", Short: "List image", Long: "List image", - Example: "ucloud image list --image-type Base", + Example: fmt.Sprintf("%s image list --image-type Base", base.BrandNameLower), Run: func(cmd *cobra.Command, args []string) { resp, err := base.BizClient.DescribeImage(req) if err != nil { @@ -175,8 +175,8 @@ func NewCmdImageCopy(out io.Writer) *cobra.Command { req.ProjectId = cmd.Flags().String("project-id", base.ConfigIns.ProjectID, "Optional. Assign project-id") req.Region = cmd.Flags().String("region", base.ConfigIns.Region, "Optional. Assign region") req.Zone = cmd.Flags().String("zone", base.ConfigIns.Zone, "Optional. Assign availability zone") - req.TargetRegion = flags.String("target-region", base.ConfigIns.Region, "Optional. Target region. See 'ucloud region'") - req.TargetProjectId = flags.String("target-project", base.ConfigIns.ProjectID, "Optional. Target Project ID. See 'ucloud project list'") + req.TargetRegion = flags.String("target-region", base.ConfigIns.Region, fmt.Sprintf("Optional. Target region. See '%s region'", base.BrandNameLower)) + req.TargetProjectId = flags.String("target-project", base.ConfigIns.ProjectID, fmt.Sprintf("Optional. Target Project ID. See '%s project list'", base.BrandNameLower)) req.TargetImageName = flags.String("target-image-name", "", "Optional. Name of target image") req.TargetImageDescription = flags.String("target-image-desc", "", "Optional. Description of target image") async = flags.Bool("async", false, "Optional. Do not wait for the long-running operation to finish.") diff --git a/cmd/mysql.go b/cmd/mysql.go index e6de66a868..27d6f98ecd 100644 --- a/cmd/mysql.go +++ b/cmd/mysql.go @@ -40,8 +40,8 @@ var poller = base.NewSpoller(describeUdbByID, base.Cxt.GetWriter()) func NewCmdMysql() *cobra.Command { cmd := &cobra.Command{ Use: "mysql", - Short: "Manipulate MySQL on UCloud platform", - Long: "Manipulate MySQL on UCloud platform", + Short: fmt.Sprintf("Manipulate MySQL on %s platform", base.BrandName), + Long: fmt.Sprintf("Manipulate MySQL on %s platform", base.BrandName), } out := base.Cxt.GetWriter() cmd.AddCommand(NewCmdMysqlDB(out)) @@ -83,8 +83,8 @@ func NewCmdMysqlCreate(out io.Writer) *cobra.Command { req := base.BizClient.NewCreateUDBInstanceRequest() cmd := &cobra.Command{ Use: "create", - Short: "Create MySQL instance on UCloud platform", - Long: "Create MySQL instance on UCloud platform", + Short: fmt.Sprintf("Create MySQL instance on %s platform", base.BrandName), + Long: fmt.Sprintf("Create MySQL instance on %s platform", base.BrandName), Run: func(c *cobra.Command, args []string) { confID = base.PickResourceID(confID) id, err := strconv.Atoi(confID) @@ -145,17 +145,17 @@ func NewCmdMysqlCreate(out io.Writer) *cobra.Command { bindZone(req, flags) req.DBTypeId = flags.String("version", "", "Required. Version of udb instance") req.Name = flags.String("name", "", "Required. Name of udb instance to create, at least 6 letters") - flags.StringVar(&confID, "conf-id", "", "Required. ConfID of configuration. see 'ucloud mysql conf list'") + flags.StringVar(&confID, "conf-id", "", fmt.Sprintf("Required. ConfID of configuration. see '%s mysql conf list'", base.BrandNameLower)) req.AdminUser = flags.String("admin-user-name", "root", "Optional. Name of udb instance's administrator") req.AdminPassword = flags.String("password", "", "Required. Password of udb instance's administrator") - flags.IntVar(&backupID, "backup-id", -1, "Optional. BackupID of the backup which the newly created UDB instance will recover from if specified. See 'ucloud mysql backup list'") + flags.IntVar(&backupID, "backup-id", -1, fmt.Sprintf("Optional. BackupID of the backup which the newly created UDB instance will recover from if specified. See '%s mysql backup list'", base.BrandNameLower)) req.Port = flags.Int("port", 3306, "Optional. Port of udb instance") flags.StringVar(&diskType, "disk-type", "", "Optional. Setting this flag means using SSD disk. Accept values: 'normal','sata_ssd','pcie_ssd'") req.DiskSpace = flags.Int("disk-size-gb", 20, "Optional. Disk size of udb instance. From 20 to 3000 according to memory size. Unit GB") req.MemoryLimit = flags.Int("memory-size-gb", 1, "Optional. Memory size of udb instance. From 1 to 128. Unit GB") req.InstanceMode = flags.String("mode", "Normal", "Optional. Mode of udb instance. Normal or HA, HA means high-availability. Both the normal and high-availability versions can create master-slave synchronization for data redundancy and read/write separation. The high-availability version provides a dual-master hot standby architecture to avoid database unavailability due to downtime or hardware failure. One more thing. It does better job for master-slave synchronization and disaster recovery using the InnoDB engine") - req.VPCId = flags.String("vpc-id", "", "Optional. Resource ID of VPC which the UDB to create belong to. See 'ucloud vpc list'") - req.SubnetId = flags.String("subnet-id", "", "Optional. Resource ID of subnet that the UDB to create belong to. See 'ucloud subnet list'") + req.VPCId = flags.String("vpc-id", "", fmt.Sprintf("Optional. Resource ID of VPC which the UDB to create belong to. See '%s vpc list'", base.BrandNameLower)) + req.SubnetId = flags.String("subnet-id", "", fmt.Sprintf("Optional. Resource ID of subnet that the UDB to create belong to. See '%s subnet list'", base.BrandNameLower)) flags.BoolVar(&async, "async", false, "Optional. Do not wait for the long-running operation to finish.") bindChargeType(req, flags) bindQuantity(req, flags) diff --git a/cmd/pathx.go b/cmd/pathx.go index 8f3d2e4f98..364a08a282 100644 --- a/cmd/pathx.go +++ b/cmd/pathx.go @@ -61,7 +61,7 @@ func NewCmdUGA3Create(out io.Writer) *cobra.Command { Use: "create", Short: "Create the pathx resource and port", Long: "Create global unified access acceleration configuration item", - Example: "ucloud pathx create --bandwidth 10 --area-code DXB" + + Example: fmt.Sprintf("%s pathx create --bandwidth 10 --area-code DXB", base.BrandNameLower) + "--charge-type Month --quantity 4 --accel Global --origin-ip 110.111.111.111" + "--protocol TCP --port 30654 --origin-port 30564", Run: func(cmd *cobra.Command, args []string) { @@ -221,7 +221,7 @@ func NewCmdUGA3Delete(out io.Writer) *cobra.Command { Use: "delete", Short: "Delete the pathx resource and port", Long: "Delete the pathx resource and port", - Example: "ucloud pathx delete --id uga3-xxx", + Example: fmt.Sprintf("%s pathx delete --id uga3-xxx", base.BrandNameLower), Run: func(cmd *cobra.Command, args []string) { if !*yes { sure, err := ux.Prompt("Are you sure you want to delete this resource ?") @@ -305,7 +305,7 @@ func NewCmdUGA3Modify(out io.Writer) *cobra.Command { Use: "modify", Short: "Modify the pathx associated information. Example bandwidth or origin information or resource information", Long: "Support modify bandwidth,origin information,resource information,port", - Example: "ucloud pathx modify --id uga3-xxx --bandwidth 1 --origin-ip 127.0.0.1 --name Pathx测试 --remark 加速资源 --protocol TCP --port 30010 --origin-port 39999", + Example: fmt.Sprintf("%s pathx modify --id uga3-xxx --bandwidth 1 --origin-ip 127.0.0.1 --name Pathx测试 --remark 加速资源 --protocol TCP --port 30010 --origin-port 39999", base.BrandNameLower), Run: func(cmd *cobra.Command, args []string) { modifyBandwidthReq.InstanceId = &instanceId modifyInstanceReq.InstanceId = &instanceId @@ -459,7 +459,7 @@ func NewCmdUGA3List(out io.Writer) *cobra.Command { Use: "list", Short: "List all the pathx resource of project", Long: "List all the pathx resource of project", - Example: "'ucloud pathx list or ucloud pathx list --id uga-xxx or ucloud pathx list --id uga-xxx --detail", + Example: fmt.Sprintf("'%s pathx list or %s pathx list --id uga-xxx or %s pathx list --id uga-xxx --detail", base.BrandNameLower, base.BrandNameLower, base.BrandNameLower), Run: func(cmd *cobra.Command, args []string) { if len(instanceId) > 0 { getPathxListReq.InstanceId = &instanceId @@ -612,7 +612,7 @@ func NewPathxPriceList(out io.Writer) *cobra.Command { Use: "list", Short: "List all the pathx acceleration area price", Long: "List all the pathx acceleration area price", - Example: "ucloud pathx price list --bandwidth 10 --area-code BKK --charge-type Month", + Example: fmt.Sprintf("%s pathx price list --bandwidth 10 --area-code BKK --charge-type Month", base.BrandNameLower), Run: func(cmd *cobra.Command, args []string) { if strings.EqualFold(*priceReq.ChargeType, "Month") { *priceReq.Quantity = 0 @@ -702,7 +702,7 @@ func NewCmdPathxAreaList(out io.Writer) *cobra.Command { Use: "list", Short: "List origin area or acceleration area information", Long: "Provide optional flags to get the optional list of global access source stations", - Example: "ucloud pathx area list --origin-ip 0.0.0.0 --origin-domain test.com", + Example: fmt.Sprintf("%s pathx area list --origin-ip 0.0.0.0 --origin-domain test.com", base.BrandNameLower), Run: func(cmd *cobra.Command, args []string) { if len(originDomain) == 0 && len(originIp) == 0 { response, err := base.BizClient.DescribeUGA3Area(areaGetReq) @@ -1184,7 +1184,7 @@ func NewCmdUGACreate(out io.Writer) *cobra.Command { Use: "create", Short: "Create uga instance", Long: "Create uga instance", - Example: "ucloud pathx uga create --name testcli1 --protocol tcp --origin-location 中国 --origin-domain lixiaojun.xyz --upath-id upath-auvfexxx/test_0 --port 80-90,100,110-115", + Example: fmt.Sprintf("%s pathx uga create --name testcli1 --protocol tcp --origin-location 中国 --origin-domain lixiaojun.xyz --upath-id upath-auvfexxx/test_0 --port 80-90,100,110-115", base.BrandNameLower), Run: func(c *cobra.Command, args []string) { if *req.IPList == "" && *req.Domain == "" { fmt.Fprintln(out, "origin-ip and origin-domain can not be both empty") @@ -1213,7 +1213,7 @@ func NewCmdUGACreate(out io.Writer) *cobra.Command { resp, err := base.BizClient.PrivatePathxClient.CreateUGAInstance(req) if err != nil { if uErr, ok := err.(uerr.Error); ok && uErr.Code() == 33756 { - fmt.Fprintf(out, "The number of ports added exceeds the limit(50). We recommend that you could reduce the number of ports, then create an uga instance, \nand then add the remaining ports by executing 'ucloud pathx uga add-port --protocol %s --uga-id --port '\n", protocol) + fmt.Fprintf(out, "The number of ports added exceeds the limit(50). We recommend that you could reduce the number of ports, then create an uga instance, \nand then add the remaining ports by executing '%s pathx uga add-port --protocol %s --uga-id --port '\n", base.BrandNameLower, protocol) } return } @@ -1246,7 +1246,7 @@ func NewCmdUGACreate(out io.Writer) *cobra.Command { req.Location = flags.String("origin-location", "", "Required. Location of origin ip or domain. accpet valeus:'中国','洛杉矶','法兰克福','中国香港','雅加达','孟买','东京','莫斯科','新加坡','曼谷','中国台北','华盛顿','首尔'") flags.StringVar(&protocol, "protocol", "", fmt.Sprintf("Required. accept values: %s", strings.Join(protocols, ","))) flags.StringSliceVar(&ports, "port", nil, "Required. Single port or port range, separated by ',', for example 80,3000-3010") - flags.StringSliceVar(&lines, "upath-id", nil, "Required. Accelerated path to bind with the uga instance to create. multiple upath-id separated by ','; see 'ucloud pathx upath list") + flags.StringSliceVar(&lines, "upath-id", nil, fmt.Sprintf("Required. Accelerated path to bind with the uga instance to create. multiple upath-id separated by ','; see '%s pathx upath list", base.BrandNameLower)) cmd.MarkFlagRequired("name") cmd.MarkFlagRequired("origin-location") diff --git a/cmd/project.go b/cmd/project.go index 1b36152a81..cefabb30f2 100644 --- a/cmd/project.go +++ b/cmd/project.go @@ -15,6 +15,7 @@ package cmd import ( + "fmt" "io" "github.com/spf13/cobra" @@ -30,7 +31,7 @@ func NewCmdProject() *cobra.Command { Use: "project", Short: "List,create,update and delete project", Long: "List,create,update and delete project", - Example: "ucloud project", + Example: fmt.Sprintf("%s project", base.BrandNameLower), } out := base.Cxt.GetWriter() cmd.AddCommand(NewCmdProjectList(out)) @@ -46,7 +47,7 @@ func NewCmdProjectList(out io.Writer) *cobra.Command { Use: "list", Short: "List project", Long: "List project", - Example: "ucloud project list", + Example: fmt.Sprintf("%s project list", base.BrandNameLower), Run: func(cmd *cobra.Command, args []string) { listProject(out) }, @@ -61,7 +62,7 @@ func NewCmdProjectCreate() *cobra.Command { Use: "create", Short: "Create project", Long: "Create project", - Example: "ucloud project create --name xxx", + Example: fmt.Sprintf("%s project create --name xxx", base.BrandNameLower), Run: func(cmd *cobra.Command, args []string) { resp, err := base.BizClient.CreateProject(req) if err != nil { @@ -88,7 +89,7 @@ func NewCmdProjectUpdate() *cobra.Command { Use: "update", Short: "Update project name", Long: "Update project name", - Example: "ucloud project update --id org-xxx --name new_name", + Example: fmt.Sprintf("%s project update --id org-xxx --name new_name", base.BrandNameLower), Run: func(cmd *cobra.Command, args []string) { resp, err := base.BizClient.ModifyProject(req) if err != nil { @@ -116,7 +117,7 @@ func NewCmdProjectDelete() *cobra.Command { Use: "delete", Short: "Delete project", Long: "Delete project", - Example: "ucloud project delete --id org-xxx", + Example: fmt.Sprintf("%s project delete --id org-xxx", base.BrandNameLower), Run: func(cmd *cobra.Command, args []string) { resp, err := base.BizClient.TerminateProject(req) if err != nil { diff --git a/cmd/region.go b/cmd/region.go index 17275532fb..dd54c8b02b 100644 --- a/cmd/region.go +++ b/cmd/region.go @@ -35,7 +35,7 @@ func NewCmdRegion(out io.Writer) *cobra.Command { Use: "region", Short: "List all region and zone", Long: "List all region and zone", - Example: "ucloud region", + Example: fmt.Sprintf("%s region", base.BrandNameLower), Run: func(cmd *cobra.Command, args []string) { regionIns, err := fetchRegion() if err != nil { diff --git a/cmd/root.go b/cmd/root.go index 283f9f4a7f..40a4a08c05 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -30,13 +30,13 @@ var global = &base.Global // NewCmdRoot 创建rootCmd rootCmd represents the base command when called without any subcommands func NewCmdRoot() *cobra.Command { cmd := &cobra.Command{ - Use: "ucloud", - Short: "UCloud CLI v" + base.Version, - Long: `UCloud CLI - manage UCloud resources and developer workflow`, + Use: base.BrandNameLower, + Short: fmt.Sprintf("%s CLI v%s", base.BrandName, base.Version), + Long: fmt.Sprintf("%s CLI - manage %s resources and developer workflow", base.BrandName, base.BrandName), DisableAutoGenTag: true, Run: func(cmd *cobra.Command, args []string) { if global.Version { - base.Cxt.Printf("ucloud cli %s\n", base.Version) + base.Cxt.Printf("%s cli %s\n", base.BrandNameLower, base.Version) } else if global.Completion { NewCmdCompletion().Run(cmd, args) } else if global.Config { @@ -55,7 +55,7 @@ func NewCmdRoot() *cobra.Command { cmd.Flags().BoolVarP(&global.Version, "version", "v", false, "Display version") cmd.Flags().BoolVar(&global.Completion, "completion", false, "Turn on auto completion according to the prompt") cmd.Flags().BoolVar(&global.Config, "config", false, "Display configuration") - cmd.Flags().BoolVar(&global.Signup, "signup", false, "Launch UCloud sign up page in browser") + cmd.Flags().BoolVar(&global.Signup, "signup", false, fmt.Sprintf("Launch %s sign up page in browser", base.BrandName)) cmd.PersistentFlags().SetFlagValuesFunc("profile", func() []string { return base.AggConfigListIns.GetProfileNameList() }) cmd.SetHelpTemplate(helpTmpl) @@ -241,11 +241,11 @@ func initialize(cmd *cobra.Command) { return } if base.ConfigIns.PrivateKey == "" { - base.Cxt.Println("private-key is empty. Execute command 'ucloud init|config' to configure it or run 'ucloud config list' to check your configurations") + base.Cxt.Printf("private-key is empty. Execute command '%s init|config' to configure it or run '%s config list' to check your configurations\n", base.BrandNameLower, base.BrandNameLower) os.Exit(0) } if base.ConfigIns.PublicKey == "" { - base.Cxt.Println("public-key is empty. Execute command 'ucloud init|config' to configure it or run 'ucloud config list' to check your configurations") + base.Cxt.Printf("public-key is empty. Execute command '%s init|config' to configure it or run '%s config list' to check your configurations\n", base.BrandNameLower, base.BrandNameLower) os.Exit(0) } } diff --git a/cmd/signature.go b/cmd/signature.go index 1e4bcc2c53..da38f5b561 100644 --- a/cmd/signature.go +++ b/cmd/signature.go @@ -8,6 +8,7 @@ import ( "github.com/fatih/color" "github.com/spf13/cobra" + "github.com/ucloud/ucloud-cli/base" "github.com/ucloud/ucloud-sdk-go/ucloud/auth" ) @@ -19,8 +20,8 @@ func NewCmdSignature() *cobra.Command { ) cmd := &cobra.Command{ Use: "signature", - Short: "Calculate ucloud signature", - Long: "Calculate ucloud signature", + Short: fmt.Sprintf("Calculate %s signature", base.BrandNameLower), + Long: fmt.Sprintf("Calculate %s signature", base.BrandNameLower), Aliases: []string{"sign"}, diff --git a/cmd/signup.go b/cmd/signup.go index 4a3ffd9391..0578da083e 100644 --- a/cmd/signup.go +++ b/cmd/signup.go @@ -20,18 +20,20 @@ import ( "runtime" "github.com/spf13/cobra" + "github.com/ucloud/ucloud-cli/base" ) // NewCmdSignup ucloud signup func NewCmdSignup() *cobra.Command { var cmd = &cobra.Command{ Use: "signup", - Short: "Launch UCloud sign up page in browser", - Long: `Launch UCloud sign up page in browser`, + Short: fmt.Sprintf("Launch %s sign up page in browser", base.BrandName), + Long: fmt.Sprintf(`Launch %s sign up page in browser`, base.BrandName), Args: cobra.NoArgs, - Example: "ucloud signup", + Example: fmt.Sprintf("%s signup", base.BrandNameLower), Run: func(cmd *cobra.Command, args []string) { - openbrowser("https://passport.ucloud.cn/#register") + url := fmt.Sprintf("%s", base.BrandRegisterURL) + openbrowser(url) }, } return cmd diff --git a/cmd/uhost.go b/cmd/uhost.go index 334410f382..9a8a1a6071 100644 --- a/cmd/uhost.go +++ b/cmd/uhost.go @@ -491,13 +491,13 @@ func NewCmdUHostCreate() *cobra.Command { req.CPU = flags.Int("cpu", 4, "Required. The count of CPU cores. Optional parameters: {1, 2, 4, 8, 12, 16, 24, 32, 64}") req.Memory = flags.Int("memory-gb", 8, "Required. Memory size. Unit: GB. Range: [1, 512], multiple of 2") flags.StringVar(&password, "password", "", "Optional. Password of the uhost user(root/ubuntu)") - flags.StringVar(&keyPairId, "key-pair-id", "", "Optional. Resource ID of ssh key pair. See 'ucloud api --Action DescribeUHostKeyPairs' Where both password and key-pair-id are set, the key-pair-id is ignored") - req.ImageId = flags.String("image-id", "", "Required. The ID of image. see 'ucloud image list'") + flags.StringVar(&keyPairId, "key-pair-id", "", fmt.Sprintf("Optional. Resource ID of ssh key pair. See '%s api --Action DescribeUHostKeyPairs' Where both password and key-pair-id are set, the key-pair-id is ignored", base.BrandNameLower)) + req.ImageId = flags.String("image-id", "", fmt.Sprintf("Required. The ID of image. see '%s image list'", base.BrandNameLower)) flags.BoolVar(&async, "async", false, "Optional. Do not wait for the long-running operation to finish.") flags.IntVar(&count, "count", 1, "Optional. Number of uhost to create.") flags.IntVar(&concurrent, "concurrent", 20, "Optional. The count of concurrent uhost creation requests.") - req.VPCId = flags.String("vpc-id", "", "Optional. VPC ID. This field is required under VPC2.0. See 'ucloud vpc list'") - req.SubnetId = flags.String("subnet-id", "", "Optional. Subnet ID. This field is required under VPC2.0. See 'ucloud subnet list'") + req.VPCId = flags.String("vpc-id", "", fmt.Sprintf("Optional. VPC ID. This field is required under VPC2.0. See '%s vpc list'", base.BrandNameLower)) + req.SubnetId = flags.String("subnet-id", "", fmt.Sprintf("Optional. Subnet ID. This field is required under VPC2.0. See '%s subnet list'", base.BrandNameLower)) req.Name = flags.String("name", "UHost", "Optional. UHost instance name") flags.StringSliceVar(&bindEipIDs, "bind-eip", nil, "Optional. Resource ID or IP Address of eip that will be bound to the new created uhost") eipReq.OperatorName = flags.String("create-eip-line", "", "Optional. BGP for regions in the chinese mainland and International for overseas regions") @@ -513,25 +513,28 @@ func NewCmdUHostCreate() *cobra.Command { bindRegion(req, flags) bindZone(req, flags) - req.MachineType = flags.String("machine-type", "N", "Optional. Accept values: N, C, G, O, OS. Forward to https://docs.ucloud.cn/api/uhost-api/uhost_type for details") + docURL := fmt.Sprintf("%s", base.BrandUhostTypeURL) + + req.MachineType = flags.String("machine-type", "N", fmt.Sprintf("Optional. Accept values: N, C, G, O, OS. Forward to %s for details", docURL)) req.MinimalCpuPlatform = flags.String("minimal-cpu-platform", "", "Optional. Accept values: Intel/Auto, Intel/IvyBridge, Intel/Haswell, Intel/Broadwell, Intel/Skylake, Intel/Cascadelake") - req.UHostType = flags.String("type", "", "Optional. Accept values: N1, N2, N3, G1, G2, G3, I1, I2, C1. Forward to https://docs.ucloud.cn/api/uhost-api/uhost_type for details") + req.UHostType = flags.String("type", "", fmt.Sprintf("Optional. Accept values: N1, N2, N3, G1, G2, G3, I1, I2, C1. Forward to %s for details", docURL)) req.GPU = flags.Int("gpu", 0, "Optional. The count of GPU cores.") + req.GpuType = flags.String("gpu-type", "", fmt.Sprintf("Optional. The type of GPU instance. Required if defined the `machine-type` as 'G'. Accept values: 'K80', 'P40', 'V100'. Forward to %s for details.", docURL)) req.NetCapability = flags.String("net-capability", "Normal", "Optional. Accept values: Normal, Super and Ultra. 'Normal' will disable network enhancement. 'Super' will enable network enhancement 1.0. 'Ultra' will enable network enhancement 2.0") flags.StringVar(&hotPlug, "hot-plug", "true", "Optional. Enable hot plug feature or not. Accept values: true or false") req.Disks[0].Type = flags.String("os-disk-type", "CLOUD_SSD", "Optional. Enumeration value. 'LOCAL_NORMAL', Ordinary local disk; 'CLOUD_NORMAL', Ordinary cloud disk; 'LOCAL_SSD',local ssd disk; 'CLOUD_SSD',cloud ssd disk; 'EXCLUSIVE_LOCAL_DISK',big data. The disk only supports a limited combination.") req.Disks[0].Size = flags.Int("os-disk-size-gb", 20, "Optional. Default 20G. Windows should be bigger than 40G Unit GB") req.Disks[0].BackupType = flags.String("os-disk-backup-type", "NONE", "Optional. Enumeration value, 'NONE' or 'DATAARK'. DataArk supports real-time backup, which can restore the disk back to any moment within the last 12 hours. (Normal Local Disk and Normal Cloud Disk Only)") - req.Disks[1].Type = flags.String("data-disk-type", "CLOUD_SSD", "Optional. Accept values: 'LOCAL_NORMAL','LOCAL_SSD','CLOUD_NORMAL',CLOUD_SSD','CLOUD_RSSD','EXCLUSIVE_LOCAL_DISK' and 'NONE'. 'LOCAL_NORMAL', Ordinary local disk; 'CLOUD_NORMAL', Ordinary cloud disk; 'LOCAL_SSD',local ssd disk; 'CLOUD_SSD',cloud ssd disk; 'CLOUD_RSSD', coud rssd disk; 'EXCLUSIVE_LOCAL_DISK',big data. The disk only supports a limited combination. 'NONE', create uhost without data disk. More details https://docs.ucloud.cn/api/uhost-api/disk_type") + req.Disks[1].Type = flags.String("data-disk-type", "CLOUD_SSD", fmt.Sprintf("Optional. Accept values: 'LOCAL_NORMAL','LOCAL_SSD','CLOUD_NORMAL',CLOUD_SSD','CLOUD_RSSD','EXCLUSIVE_LOCAL_DISK' and 'NONE'. 'LOCAL_NORMAL', Ordinary local disk; 'CLOUD_NORMAL', Ordinary cloud disk; 'LOCAL_SSD',local ssd disk; 'CLOUD_SSD',cloud ssd disk; 'CLOUD_RSSD', coud rssd disk; 'EXCLUSIVE_LOCAL_DISK',big data. The disk only supports a limited combination. 'NONE', create uhost without data disk. More details %s", base.BrandDiskTypeURL)) req.Disks[1].Size = flags.Int("data-disk-size-gb", 20, "Optional. Disk size. Unit GB") req.Disks[1].BackupType = flags.String("data-disk-backup-type", "NONE", "Optional. Enumeration value, 'NONE' or 'DATAARK'. DataArk supports real-time backup, which can restore the disk back to any moment within the last 12 hours. (Normal Local Disk and Normal Cloud Disk Only)") - flags.StringVar(&firewallId, "firewall-id", "", "Optional. Firewall Id, default: Web recommended firewall. see 'ucloud firewall list'.") + flags.StringVar(&firewallId, "firewall-id", "", fmt.Sprintf("Optional. Firewall Id, default: Web recommended firewall. see '%s firewall list'.", base.BrandNameLower)) flags.StringSliceVar(&secGroupIds, "security-group-id", nil, "Optional. Security Group Id. Before using security group function, please confirm the account has such permission. When both firewall-id and security-group-id are set, the security-group-id will be ignored") req.Tag = flags.String("group", "Default", "Optional. Business group") - req.IsolationGroup = flags.String("isolation-group", "", "Optional. Resource ID of isolation group. see 'ucloud uhost isolation-group list") - req.GpuType = flags.String("gpu-type", "", "Optional. The type of GPU instance. Required if defined the `machine-type` as 'G'. Accept values: 'K80', 'P40', 'V100'. Forward to https://docs.ucloud.cn/api/uhost-api/uhost_type for details.") - flags.StringVar(&userData, "user-data", "", "Optional. Conflicts with `user-data-base64`. ConCustomize the startup behaviors when launching the instance. Forward to https://docs.ucloud.cn/uhost/guide/metadata/userdata for details.") - flags.StringVar(&userDataBase64, "user-data-base64", "", "Optional. Conflicts with `user-data`. Customize the startup behaviors when launching the instance. The value must be base64-encode. Forward to https://docs.ucloud.cn/uhost/guide/metadata/userdata for details.") + req.IsolationGroup = flags.String("isolation-group", "", fmt.Sprintf("Optional. Resource ID of isolation group. see '%s uhost isolation-group list'", base.BrandNameLower)) + userDataDocURL := fmt.Sprintf("%s", base.BrandUserDataURL) + flags.StringVar(&userData, "user-data", "", fmt.Sprintf("Optional. Conflicts with `user-data-base64`. Customize the startup behaviors when launching the instance. Forward to %s for details.", userDataDocURL)) + flags.StringVar(&userDataBase64, "user-data-base64", "", fmt.Sprintf("Optional. Conflicts with `user-data`. Customize the startup behaviors when launching the instance. The value must be base64-encode. Forward to %s for details.", userDataDocURL)) flags.MarkDeprecated("type", "please use --machine-type instead") flags.SetFlagValues("charge-type", "Month", "Year", "Dynamic", "Trial") @@ -918,7 +921,7 @@ func NewCmdUHostStop(out io.Writer) *cobra.Command { Use: "stop", Short: "Shut down uhost instance", Long: "Shut down uhost instance", - Example: "ucloud uhost stop --uhost-id uhost-xxx1,uhost-xxx2", + Example: fmt.Sprintf("%s uhost stop --uhost-id uhost-xxx1,uhost-xxx2", base.BrandNameLower), Run: func(cmd *cobra.Command, args []string) { for _, id := range *uhostIDs { id = base.PickResourceID(id) @@ -996,7 +999,7 @@ func NewCmdUHostStart(out io.Writer) *cobra.Command { Use: "start", Short: "Start Uhost instance", Long: "Start Uhost instance", - Example: "ucloud uhost start --uhost-id uhost-xxx1,uhost-xxx2", + Example: fmt.Sprintf("%s uhost start --uhost-id uhost-xxx1,uhost-xxx2", base.BrandNameLower), Run: func(cmd *cobra.Command, args []string) { for _, id := range *uhostIDs { id := base.PickResourceID(id) @@ -1038,7 +1041,7 @@ func NewCmdUHostReboot(out io.Writer) *cobra.Command { Use: "restart", Short: "Restart uhost instance", Long: "Restart uhost instance", - Example: "ucloud uhost restart --uhost-id uhost-xxx1,uhost-xxx2", + Example: fmt.Sprintf("%s uhost restart --uhost-id uhost-xxx1,uhost-xxx2", base.BrandNameLower), Run: func(cmd *cobra.Command, args []string) { for _, id := range *uhostIDs { id = base.PickResourceID(id) @@ -1081,7 +1084,7 @@ func NewCmdUHostPoweroff(out io.Writer) *cobra.Command { Use: "poweroff", Short: "Analog power off Uhost instnace", Long: "Analog power off Uhost instnace", - Example: "ucloud uhost poweroff --uhost-id uhost-xxx1,uhost-xxx2", + Example: fmt.Sprintf("%s uhost poweroff --uhost-id uhost-xxx1,uhost-xxx2", base.BrandNameLower), Run: func(cmd *cobra.Command, args []string) { if !*yes { confirmText := "Danger, it may affect data integrity. Are you sure you want to poweroff this uhost?" @@ -1172,7 +1175,7 @@ func NewCmdUHostResize(out io.Writer) *cobra.Command { Use: "resize", Short: "Resize uhost instance,such as cpu core count, memory size and disk size", Long: "Resize uhost instance,such as cpu core count, memory size and disk size", - Example: "ucloud uhost resize --uhost-id uhost-xxx1,uhost-xxx2 --cpu 4 --memory-gb 8", + Example: fmt.Sprintf("%s uhost resize --uhost-id uhost-xxx1,uhost-xxx2 --cpu 4 --memory-gb 8", base.BrandNameLower), Run: func(cmd *cobra.Command, args []string) { if *req.CPU == 0 { req.CPU = nil @@ -1473,7 +1476,7 @@ func NewCmdUHostClone(out io.Writer) *cobra.Command { flags.SortFlags = false uhostID = flags.String("uhost-id", "", "Required. Resource ID of the uhost to clone from") flags.StringVar(&password, "password", "", "Optional. Password of the uhost user(root/ubuntu)") - flags.StringVar(&keyPairId, "key-pair-id", "", "Optional. Resource ID of ssh key pair. See 'ucloud api --Action DescribeUHostKeyPairs' Where both password and key-pair-id are set, the key-pair-id is ignored") + flags.StringVar(&keyPairId, "key-pair-id", "", fmt.Sprintf("Optional. Resource ID of ssh key pair. See '%s api --Action DescribeUHostKeyPairs' Where both password and key-pair-id are set, the key-pair-id is ignored", base.BrandNameLower)) req.Name = flags.String("name", "", "Optional. Name of the uhost to clone") req.ProjectId = flags.String("project-id", base.ConfigIns.ProjectID, "Optional. Assign project-id") @@ -1703,8 +1706,8 @@ func NewCmdUhostReinstallOS(out io.Writer) *cobra.Command { flags.SortFlags = false req.UHostId = flags.String("uhost-id", "", "Required. Resource ID of the uhost to reinstall operating system") flags.StringVar(&password, "password", "", "Optional. Password of the uhost user(root/ubuntu)") - flags.StringVar(&keyPairId, "key-pair-id", "", "Optional. Resource ID of ssh key pair. See 'ucloud api --Action DescribeUHostKeyPairs' Where both password and key-pair-id are set, the key-pair-id is ignored") - req.ImageId = flags.String("image-id", "", "Optional. Resource ID the image to install. See 'ucloud image list'. Default is original image of the uhost") + flags.StringVar(&keyPairId, "key-pair-id", "", fmt.Sprintf("Optional. Resource ID of ssh key pair. See '%s api --Action DescribeUHostKeyPairs' Where both password and key-pair-id are set, the key-pair-id is ignored", base.BrandNameLower)) + req.ImageId = flags.String("image-id", "", fmt.Sprintf("Optional. Resource ID the image to install. See '%s image list'. Default is original image of the uhost", base.BrandNameLower)) req.ProjectId = flags.String("project-id", base.ConfigIns.ProjectID, "Optional. Assign project-id") req.Region = flags.String("region", base.ConfigIns.Region, "Optional. Assign region") req.Zone = flags.String("zone", base.ConfigIns.Zone, "Optional. Assign availability zone") diff --git a/cmd/ulb.go b/cmd/ulb.go index 168628326b..1681210a03 100644 --- a/cmd/ulb.go +++ b/cmd/ulb.go @@ -192,8 +192,8 @@ func NewCmdULBCreate(out io.Writer) *cobra.Command { flags.StringVar(&mode, "mode", "outer", "Required. Network mode of ULB instance, outer or inner.") bindRegion(req, flags) bindProjectID(req, flags) - req.VPCId = flags.String("vpc-id", "", "Optional. Resource ID of VPC which the ULB to create belong to. See 'ucloud vpc list'") - req.SubnetId = flags.String("subnet-id", "", "Optional. Resource ID of subnet. This flag will be discarded when you are creating an outter mode ULB. See 'ucloud subnet list'") + req.VPCId = flags.String("vpc-id", "", fmt.Sprintf("Optional. Resource ID of VPC which the ULB to create belong to. See '%s vpc list'", base.BrandNameLower)) + req.SubnetId = flags.String("subnet-id", "", fmt.Sprintf("Optional. Resource ID of subnet. This flag will be discarded when you are creating an outter mode ULB. See '%s subnet list'", base.BrandNameLower)) req.ChargeType = flags.String("charge-type", "Month", "Optional.'Year',pay yearly;'Month',pay monthly;'Dynamic', pay hourly") req.Tag = flags.String("group", "Default", "Optional. Business group") req.Remark = flags.String("remark", "", "Optional. Remark of instance to create.") diff --git a/cmd/umem.go b/cmd/umem.go index 3964e9af8a..5f08b9594f 100644 --- a/cmd/umem.go +++ b/cmd/umem.go @@ -209,8 +209,8 @@ func NewCmdRedisCreate(out io.Writer) *cobra.Command { flags.StringVar(&redisType, "type", "", "Required. Type of the redis. Accept values:'master-replica','distributed'") req.Size = flags.Int("size-gb", 1, "Optional. Memory size. Default value 1GB(for master-replica redis type) or 16GB(for distributed redis type). Unit GB") req.Version = flags.String("version", "3.2", "Optional. Version of redis") - req.VPCId = flags.String("vpc-id", "", "Optional. VPC ID. This field is required under VPC2.0. See 'ucloud vpc list'") - req.SubnetId = flags.String("subnet-id", "", "Optional. Subnet ID. This field is required under VPC2.0. See 'ucloud subnet list'") + req.VPCId = flags.String("vpc-id", "", fmt.Sprintf("Optional. VPC ID. This field is required under VPC2.0. See '%s vpc list'", base.BrandNameLower)) + req.SubnetId = flags.String("subnet-id", "", fmt.Sprintf("Optional. Subnet ID. This field is required under VPC2.0. See '%s subnet list'", base.BrandNameLower)) flags.StringVar(&password, "password", "", "Optional. Password of redis to create") bindRegion(req, flags) @@ -243,7 +243,7 @@ func NewCmdRedisDelete(out io.Writer) *cobra.Command { Use: "delete", Short: "Delete redis instances", Long: "Delete redis instances", - Example: "ucloud redis delete --umem-id uredis-rl5xuxx/testcli1,uredis-xsdfa/testcli2", + Example: fmt.Sprintf("%s redis delete --umem-id uredis-rl5xuxx/testcli1,uredis-xsdfa/testcli2", base.BrandNameLower), Run: func(c *cobra.Command, args []string) { for _, idname := range idNames { id := base.PickResourceID(idname) @@ -455,8 +455,8 @@ func NewCmdMemcacheCreate(out io.Writer) *cobra.Command { req.Name = flags.String("name", "", "Required. Name of memcache instance to create") req.Size = flags.Int("size-gb", 1, "Optional. Memory size of memcache instance. Unit GB. Accpet values:1,2,4,8,16,32") - req.VPCId = flags.String("vpc-id", "", "Optional. VPC ID. See 'ucloud vpc list'") - req.SubnetId = flags.String("subnet-id", "", "Optional. Subnet ID. See 'ucloud subnet list'") + req.VPCId = flags.String("vpc-id", "", fmt.Sprintf("Optional. VPC ID. See '%s vpc list'", base.BrandNameLower)) + req.SubnetId = flags.String("subnet-id", "", fmt.Sprintf("Optional. Subnet ID. See '%s subnet list'", base.BrandNameLower)) bindProjectID(req, flags) bindRegion(req, flags) bindZone(req, flags) @@ -485,7 +485,7 @@ func NewCmdMemcacheDelete(out io.Writer) *cobra.Command { Use: "delete", Short: "Delete memcache instances", Long: "Delete memcache instances", - Example: "ucloud memcache delete --umem-id umemcache-rl5xuxx/testcli1,umemcache-xsdfa/testcli2", + Example: fmt.Sprintf("%s memcache delete --umem-id umemcache-rl5xuxx/testcli1,umemcache-xsdfa/testcli2", base.BrandNameLower), Run: func(c *cobra.Command, args []string) { for _, idname := range idNames { id := base.PickResourceID(idname) diff --git a/cmd/unet.go b/cmd/unet.go index f4dead67c2..0e77856d93 100644 --- a/cmd/unet.go +++ b/cmd/unet.go @@ -72,7 +72,7 @@ func NewCmdUDPNCreate(out io.Writer) *cobra.Command { req.Bandwidth = flags.Int("bandwidth-mb", 0, "Required. Bandwidth of the tunnel to create. Unit:Mb. Rnange [2,1000]") req.ChargeType = flags.String("charge-type", "", "Optional. Enumeration value.'Year',pay yearly;'Month',pay monthly;'Dynamic', pay hourly") req.Quantity = cmd.Flags().Int("quantity", 1, "Optional. The duration of the instance. N years/months.") - req.ProjectId = flags.String("project-id", base.ConfigIns.ProjectID, "Optional. Project-id, see 'ucloud project list'") + req.ProjectId = flags.String("project-id", base.ConfigIns.ProjectID, fmt.Sprintf("Optional. Project-id, see '%s project list'", base.BrandNameLower)) flags.SetFlagValues("charge-type", "Month", "Year", "Dynamic") flags.SetFlagValuesFunc("project-id", getProjectList) @@ -139,8 +139,8 @@ func NewCmdUDPNList(out io.Writer) *cobra.Command { req.UDPNId = flags.String("udpn-id", "", "Optional. Resource ID of udpn instances to list") req.Offset = flags.Int("offset", 0, "Optional. Offset") req.Limit = flags.Int("limit", 50, "Optional. Limit") - req.Region = flags.String("region", base.ConfigIns.Region, "Optional. Region, see 'ucloud region'") - req.ProjectId = flags.String("project-id", base.ConfigIns.ProjectID, "Optional. Project-id, see 'ucloud project list'") + req.Region = flags.String("region", base.ConfigIns.Region, fmt.Sprintf("Optional. Region, see '%s region'", base.BrandNameLower)) + req.ProjectId = flags.String("project-id", base.ConfigIns.ProjectID, fmt.Sprintf("Optional. Project-id, see '%s project list'", base.BrandNameLower)) flags.SetFlagValuesFunc("region", getRegionList) flags.SetFlagValuesFunc("project-id", getRegionList) @@ -175,7 +175,7 @@ func NewCmdUdpnDelete(out io.Writer) *cobra.Command { flags.SortFlags = false flags.StringSliceVar(&idNames, "udpn-id", nil, "Required. Resource ID of udpn instances to delete") - req.ProjectId = flags.String("project-id", base.ConfigIns.ProjectID, "Optional. Project-id, see 'ucloud project list'") + req.ProjectId = flags.String("project-id", base.ConfigIns.ProjectID, fmt.Sprintf("Optional. Project-id, see '%s project list'", base.BrandNameLower)) flags.SetFlagValuesFunc("project-id", getRegionList) flags.SetFlagValuesFunc("udpn-id", func() []string { @@ -212,8 +212,8 @@ func NewCmdUdpnModifyBW(out io.Writer) *cobra.Command { flags.StringSliceVar(&idNames, "udpn-id", nil, "Required. Resource ID of UDPN to modify bandwidth") req.Bandwidth = flags.Int("bandwidth-mb", 0, "Required. Bandwidth of UDPN tunnel. Unit:Mb. Range [2,1000]") - req.Region = flags.String("region", base.ConfigIns.Region, "Optional. Region, see 'ucloud region'") - req.ProjectId = flags.String("project-id", base.ConfigIns.ProjectID, "Optional. Project-id, see 'ucloud project list'") + req.Region = flags.String("region", base.ConfigIns.Region, fmt.Sprintf("Optional. Region, see '%s region'", base.BrandNameLower)) + req.ProjectId = flags.String("project-id", base.ConfigIns.ProjectID, fmt.Sprintf("Optional. Project-id, see '%s project list'", base.BrandNameLower)) flags.SetFlagValuesFunc("udpn-id", func() []string { return getAllUDPNIdNames(*req.ProjectId, *req.Region) diff --git a/cmd/util.go b/cmd/util.go index 3a0347bdfa..6b414a8914 100644 --- a/cmd/util.go +++ b/cmd/util.go @@ -17,20 +17,20 @@ import ( func bindRegion(req request.Common, flags *pflag.FlagSet) { var region string - flags.StringVar(®ion, "region", base.ConfigIns.Region, "Optional. Override default region for this command invocation, see 'ucloud region'") + flags.StringVar(®ion, "region", base.ConfigIns.Region, fmt.Sprintf("Optional. Override default region for this command invocation, see '%s region'", base.BrandNameLower)) flags.SetFlagValuesFunc("region", getRegionList) req.SetRegionRef(®ion) } func bindRegionS(region *string, flags *pflag.FlagSet) { *region = base.ConfigIns.Region - flags.StringVar(region, "region", base.ConfigIns.Region, "Optional. Override default region for this command invocation, see 'ucloud region'") + flags.StringVar(region, "region", base.ConfigIns.Region, fmt.Sprintf("Optional. Override default region for this command invocation, see '%s region'", base.BrandNameLower)) flags.SetFlagValuesFunc("region", getRegionList) } func bindZone(req request.Common, flags *pflag.FlagSet) { var zone string - flags.StringVar(&zone, "zone", base.ConfigIns.Zone, "Optional. Override default availability zone for this command invocation, see 'ucloud region'") + flags.StringVar(&zone, "zone", base.ConfigIns.Zone, fmt.Sprintf("Optional. Override default availability zone for this command invocation, see '%s region'", base.BrandNameLower)) flags.SetFlagValuesFunc("zone", func() []string { return getZoneList(req.GetRegion()) }) @@ -39,7 +39,7 @@ func bindZone(req request.Common, flags *pflag.FlagSet) { func bindZoneEmpty(req request.Common, flags *pflag.FlagSet) { var zone string - flags.StringVar(&zone, "zone", "", "Optional. Override default availability zone for this command invocation, see 'ucloud region'") + flags.StringVar(&zone, "zone", "", fmt.Sprintf("Optional. Override default availability zone for this command invocation, see '%s region'", base.BrandNameLower)) flags.SetFlagValuesFunc("zone", func() []string { return getZoneList(req.GetRegion()) }) @@ -47,7 +47,7 @@ func bindZoneEmpty(req request.Common, flags *pflag.FlagSet) { } func bindZoneEmptyS(zone, region *string, flags *pflag.FlagSet) { - flags.StringVar(zone, "zone", "", "Optional. Override default availability zone for this command invocation, see 'ucloud region'") + flags.StringVar(zone, "zone", "", fmt.Sprintf("Optional. Override default availability zone for this command invocation, see '%s region'", base.BrandNameLower)) flags.SetFlagValuesFunc("zone", func() []string { return getZoneList(*region) }) @@ -55,7 +55,7 @@ func bindZoneEmptyS(zone, region *string, flags *pflag.FlagSet) { func bindZoneS(zone, region *string, flags *pflag.FlagSet) { *zone = base.ConfigIns.Zone - flags.StringVar(zone, "zone", base.ConfigIns.Zone, "Optional. Override default availability zone for this command invocation, see 'ucloud region'") + flags.StringVar(zone, "zone", base.ConfigIns.Zone, fmt.Sprintf("Optional. Override default availability zone for this command invocation, see '%s region'", base.BrandNameLower)) flags.SetFlagValuesFunc("zone", func() []string { return getZoneList(*region) }) @@ -63,14 +63,14 @@ func bindZoneS(zone, region *string, flags *pflag.FlagSet) { func bindProjectID(req request.Common, flags *pflag.FlagSet) { var project string - flags.StringVar(&project, "project-id", base.ConfigIns.ProjectID, "Optional. Override default project-id for this command invocation, see 'ucloud project list'") + flags.StringVar(&project, "project-id", base.ConfigIns.ProjectID, fmt.Sprintf("Optional. Override default project-id for this command invocation, see '%s project list'", base.BrandNameLower)) flags.SetFlagValuesFunc("project-id", getProjectList) req.SetProjectIdRef(&project) } func bindProjectIDS(project *string, flags *pflag.FlagSet) { *project = base.ConfigIns.ProjectID - flags.StringVar(project, "project-id", base.ConfigIns.ProjectID, "Optional. Override default project-id for this command invocation, see 'ucloud project list'") + flags.StringVar(project, "project-id", base.ConfigIns.ProjectID, fmt.Sprintf("Optional. Override default project-id for this command invocation, see '%s project list'", base.BrandNameLower)) flags.SetFlagValuesFunc("project-id", getProjectList) } diff --git a/cmd/vpc.go b/cmd/vpc.go index f6ecd02db9..b7fb0a9e80 100644 --- a/cmd/vpc.go +++ b/cmd/vpc.go @@ -77,8 +77,8 @@ func NewCmdVPCList(out io.Writer) *cobra.Command { } flags := cmd.Flags() flags.SortFlags = false - req.Region = flags.String("region", base.ConfigIns.Region, "Optional. Region, see 'ucloud region'") - req.ProjectId = flags.String("project-id", base.ConfigIns.ProjectID, "Optional. Project-id, see 'ucloud project list'") + req.Region = flags.String("region", base.ConfigIns.Region, fmt.Sprintf("Optional. Region, see '%s region'", base.BrandNameLower)) + req.ProjectId = flags.String("project-id", base.ConfigIns.ProjectID, fmt.Sprintf("Optional. Project-id, see '%s project list'", base.BrandNameLower)) req.Tag = flags.String("group", "", "Optional. Group") flags.StringSliceVar(&vpcIDs, "vpc-id", []string{}, "Optional. Multiple values separated by commas") @@ -97,7 +97,7 @@ func NewCmdVpcCreate() *cobra.Command { Use: "create", Short: "Create vpc network", Long: "Create vpc network", - Example: "ucloud vpc create --name xxx --segment 192.168.0.0/16", + Example: fmt.Sprintf("%s vpc create --name xxx --segment 192.168.0.0/16", base.BrandNameLower), Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { req.Network = *segments @@ -137,7 +137,7 @@ func NewCmdVpcDelete() *cobra.Command { Use: "delete", Short: "Delete vpc network", Long: "Delete vpc network", - Example: "ucloud vpc delete --vpc-id uvnet-xxx", + Example: fmt.Sprintf("%s vpc delete --vpc-id uvnet-xxx", base.BrandNameLower), Run: func(cmd *cobra.Command, args []string) { for _, idname := range idNames { req.VPCId = sdk.String(base.PickResourceID(idname)) @@ -173,7 +173,7 @@ func NewCmdVpcCreatePeer() *cobra.Command { Use: "create-intercome", Short: "Create intercome with other vpc", Long: "Create intercome with other vpc", - Example: "ucloud vpc create-intercome --vpc-id xx --dst-vpc-id xx --dst-region xx", + Example: fmt.Sprintf("%s vpc create-intercome --vpc-id xx --dst-vpc-id xx --dst-region xx", base.BrandNameLower), Run: func(cmd *cobra.Command, args []string) { req.ProjectId = sdk.String(base.PickResourceID(*req.ProjectId)) req.DstProjectId = sdk.String(base.PickResourceID(*req.DstProjectId)) @@ -231,7 +231,7 @@ func NewCmdVpcListPeer(out io.Writer) *cobra.Command { Use: "list-intercome", Short: "list intercome ", Long: "list intercome", - Example: "ucloud vpc list-intercome --vpc-id xx", + Example: fmt.Sprintf("%s vpc list-intercome --vpc-id xx", base.BrandNameLower), Run: func(cmd *cobra.Command, args []string) { req.VPCId = sdk.String(base.PickResourceID(*req.VPCId)) resp, err := base.BizClient.DescribeVPCIntercom(req) @@ -275,7 +275,7 @@ func NewCmdVpcDeletePeer() *cobra.Command { Use: "delete-intercome", Short: "delete the vpc intercome", Long: "delete the vpc intercome", - Example: "ucloud vpc delete-intercome --vpc-id xxx --dst-vpc-id xxx", + Example: fmt.Sprintf("%s vpc delete-intercome --vpc-id xxx --dst-vpc-id xxx", base.BrandNameLower), Run: func(cmd *cobra.Command, args []string) { req.VPCId = sdk.String(base.PickResourceID(*req.VPCId)) req.DstVPCId = sdk.String(base.PickResourceID(*req.DstVPCId)) @@ -389,8 +389,8 @@ func NewCmdSubnetList(out io.Writer) *cobra.Command { flags := cmd.Flags() flags.SortFlags = false - req.Region = flags.String("region", base.ConfigIns.Region, "Optional. Region, see 'ucloud region'") - req.ProjectId = flags.String("project-id", base.ConfigIns.ProjectID, "Optional. Project-id, see 'ucloud project list'") + req.Region = flags.String("region", base.ConfigIns.Region, fmt.Sprintf("Optional. Region, see '%s region'", base.BrandNameLower)) + req.ProjectId = flags.String("project-id", base.ConfigIns.ProjectID, fmt.Sprintf("Optional. Project-id, see '%s project list'", base.BrandNameLower)) flags.StringSliceVar(&req.SubnetIds, "subnet-id", []string{}, "Optional. Multiple values separated by commas") req.VPCId = flags.String("vpc-id", "", "Optional. Resource ID of VPC") req.Tag = flags.String("group", "", "Optional. Group") @@ -408,7 +408,7 @@ func NewCmdSubnetCreate() *cobra.Command { Use: "create", Short: "Create subnet of vpc network", Long: "Create subnet of vpc network", - Example: "ucloud subnet create --vpc-id uvnet-vpcxid --name testName --segment 192.168.2.0/24", + Example: fmt.Sprintf("%s subnet create --vpc-id uvnet-vpcxid --name testName --segment 192.168.2.0/24", base.BrandNameLower), Run: func(cmd *cobra.Command, args []string) { ipMaskStrs := strings.SplitN(segment.String(), "/", 2) req.Subnet = sdk.String(ipMaskStrs[0]) From d09dda0681a5415777e04190843b96c45922cbe1 Mon Sep 17 00:00:00 2001 From: Episkey <70593980+Episkey-G@users.noreply.github.com> Date: Wed, 7 May 2025 10:43:57 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat=EF=BC=9Arm=20DasERL=20(#92)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: externalize UCloud literals to ldflags variables * fix: ucloud.cn to ldflags variables * fix: split combined URL into separate config variables * feat: rm DasERL --------- Co-authored-by: run.gu --- base/branding.go | 1 - base/log.go | 40 ---------------------------------------- go.sum | 2 -- 3 files changed, 43 deletions(-) diff --git a/base/branding.go b/base/branding.go index a154d7774c..334ab19978 100644 --- a/base/branding.go +++ b/base/branding.go @@ -6,7 +6,6 @@ var ( BrandNameLower = "ucloud" BrandAPIURL = "https://api.ucloud.cn/" BrandUmountURL = "https://docs.ucloud.cn/storage_cdn/udisk/userguide/umount" - BrandLogURL = "https://das-rpt.ucloud.cn/log" BrandAuthURL = "https://accountv2.ucloud.cn/authentication" BrandAccountURL = "https://accountv2.ucloud.cn" BrandRegisterURL = "https://passport.ucloud.cn/#register" diff --git a/base/log.go b/base/log.go index d22f1685e3..eddfd82f39 100644 --- a/base/log.go +++ b/base/log.go @@ -1,12 +1,9 @@ package base import ( - "bytes" "encoding/json" "fmt" - "net/http" "os" - "runtime" "strings" "sync" "time" @@ -15,21 +12,12 @@ import ( log "github.com/sirupsen/logrus" "github.com/ucloud/ucloud-sdk-go/ucloud/request" - "github.com/ucloud/ucloud-sdk-go/ucloud/version" ) -// DefaultDasURL location of das server -var DefaultDasURL string - -func init() { - DefaultDasURL = fmt.Sprintf("%s", BrandLogURL) -} - // Logger 日志 var logger *log.Logger var mu sync.Mutex var out = Cxt.GetWriter() -var tracer = Tracer{DefaultDasURL} func initConfigDir() { if _, err := os.Stat(GetLogFileDir()); os.IsNotExist(err) { @@ -160,7 +148,6 @@ func UploadLogs(logs []string, level string, goID int64) { line := fmt.Sprintf("time=%s level=%s goroutine_id=%d msg=%s", time.Now().Format(time.RFC3339Nano), level, goID, log) lines = append(lines, line) } - tracer.Send(lines) } // LogRotateHook rotate log file @@ -270,30 +257,3 @@ func (t Tracer) wrapLogs(log []string) ([]byte, error) { } return marshaled, nil } - -// Send logs to server -func (t Tracer) Send(logs []string) error { - body, err := t.wrapLogs(logs) - if err != nil { - return err - } - for i := 0; i < len(body); i++ { - body[i] = ^body[i] - } - - client := &http.Client{} - ua := fmt.Sprintf("GO/%s GO-SDK/%s %s", runtime.Version(), version.Version, UserAgent) - req, err := http.NewRequest("POST", t.DasUrl, bytes.NewReader(body)) - req.Header.Add("Origin", "https://sdk.ucloud.cn") - req.Header.Add("User-Agent", ua) - resp, err := client.Do(req) - if err != nil { - return err - } - defer resp.Body.Close() - if resp.StatusCode != 200 { - return fmt.Errorf("send logs failed: status %d %s", resp.StatusCode, resp.Status) - } - - return nil -} diff --git a/go.sum b/go.sum index 587a20d04f..83d4daf9eb 100644 --- a/go.sum +++ b/go.sum @@ -49,8 +49,6 @@ github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DM github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/ucloud/ucloud-sdk-go v0.22.17 h1:EFn+GxVKS5Tj8hIPie3qL6Zgk25fmWcHqJ06K8wl+Qo= -github.com/ucloud/ucloud-sdk-go v0.22.17/go.mod h1:dyLmFHmUfgb4RZKYQP9IArlvQ2pxzFthfhwxRzOEPIw= github.com/ucloud/ucloud-sdk-go v0.22.25 h1:ceKeH7WFnpUt9nJSubn+mnxS1iKGrk/Q+HLwa0iYwmQ= github.com/ucloud/ucloud-sdk-go v0.22.25/go.mod h1:dyLmFHmUfgb4RZKYQP9IArlvQ2pxzFthfhwxRzOEPIw= github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=