@@ -36,7 +36,7 @@ const DefaultBaseURL = "https://api.ucloud.cn/"
3636const DefaultProfile = "default"
3737
3838//Version 版本号
39- const Version = "0.1.25 "
39+ const Version = "0.1.26 "
4040
4141//ConfigIns 配置实例, 程序加载时生成
4242var ConfigIns = & AggConfig {
@@ -138,10 +138,24 @@ func (p *AggConfig) ConfigPrivateKey() error {
138138 return nil
139139}
140140
141+ //ConfigBaseURL 输入BaseURL
142+ func (p * AggConfig ) ConfigBaseURL () error {
143+ fmt .Printf ("Default base-url(%s):" , DefaultBaseURL )
144+ _ , err := fmt .Scanf ("%s\n " , & p .BaseURL )
145+ if err != nil {
146+ return err
147+ }
148+ p .BaseURL = strings .TrimSpace (p .BaseURL )
149+ if len (p .BaseURL ) == 0 {
150+ p .BaseURL = DefaultBaseURL
151+ }
152+ return nil
153+ }
154+
141155//ConfigUploadLog agree upload log or not
142156func (p * AggConfig ) ConfigUploadLog () error {
143157 var input string
144- fmt .Print ("Do you agree to upload log in local file ~/.ucloud/cli.log to help ucloud-cli get better(yes/ no):" )
158+ fmt .Print ("Do you agree to upload log in local file ~/.ucloud/cli.log to help ucloud-cli get better(yes| no):" )
145159 _ , err := fmt .Scanf ("%s\n " , & input )
146160 if err != nil {
147161 HandleError (err )
@@ -578,39 +592,19 @@ func GetBizClient(ac *AggConfig) (*Client, error) {
578592 if err != nil {
579593 err = fmt .Errorf ("parse timeout %ds failed: %v" , ac .Timeout , err )
580594 }
581- baseURL := ac .BaseURL
582- if Global .BaseURL != "" {
583- baseURL = Global .BaseURL
584- }
585- if Global .Timeout != 0 {
586- timeout = time .Duration (Global .Timeout ) * time .Second
587- }
588- maxRetryTimes := * ac .MaxRetryTimes
589- if Global .MaxRetryTimes != - 1 {
590- maxRetryTimes = Global .MaxRetryTimes
591- }
592595 ClientConfig = & sdk.Config {
593- BaseUrl : baseURL ,
596+ BaseUrl : ac . BaseURL ,
594597 Timeout : timeout ,
595598 UserAgent : fmt .Sprintf ("UCloud-CLI/%s" , Version ),
596599 LogLevel : log .FatalLevel ,
597600 Region : ac .Region ,
598601 ProjectId : ac .ProjectID ,
599- MaxRetries : maxRetryTimes ,
602+ MaxRetries : * ac . MaxRetryTimes ,
600603 }
601-
602- if Global .PublicKey != "" && Global .PrivateKey != "" {
603- AuthCredential = & auth.Credential {
604- PublicKey : Global .PublicKey ,
605- PrivateKey : Global .PrivateKey ,
606- }
607- } else {
608- AuthCredential = & auth.Credential {
609- PublicKey : ac .PublicKey ,
610- PrivateKey : ac .PrivateKey ,
611- }
604+ AuthCredential = & auth.Credential {
605+ PublicKey : ac .PublicKey ,
606+ PrivateKey : ac .PrivateKey ,
612607 }
613-
614608 return NewClient (ClientConfig , AuthCredential ), err
615609}
616610
@@ -641,9 +635,9 @@ func InitConfig() {
641635
642636 if ins != nil {
643637 ConfigIns = ins
644- } else {
645- ins = ConfigIns
646638 }
639+
640+ mergeConfigIns (ConfigIns )
647641 logCmd ()
648642
649643 bc , err := GetBizClient (ConfigIns )
@@ -655,6 +649,23 @@ func InitConfig() {
655649 }
656650}
657651
652+ func mergeConfigIns (ins * AggConfig ) {
653+ if Global .BaseURL != "" {
654+ ins .BaseURL = Global .BaseURL
655+ }
656+ if Global .Timeout != 0 {
657+ ins .Timeout = Global .Timeout
658+ }
659+ if Global .MaxRetryTimes != - 1 {
660+ ins .MaxRetryTimes = sdk .Int (Global .MaxRetryTimes )
661+ }
662+
663+ if Global .PublicKey != "" && Global .PrivateKey != "" {
664+ ins .PrivateKey = Global .PrivateKey
665+ ins .PublicKey = Global .PublicKey
666+ }
667+ }
668+
658669func init () {
659670 //配置日志
660671 err := initLog ()
0 commit comments