77 "time"
88)
99
10- type NotExistsError struct {
11- err error
12- }
10+ type NotExistsError struct {}
1311
1412func (e * NotExistsError ) Error () string {
1513 return "object does not exist"
@@ -32,7 +30,7 @@ func (sty *Strategy) ExecuteCommand(cmd string, nonFlagArgs []string) error {
3230 switch cmd {
3331 case "put" :
3432 if len (nonFlagArgs ) != 3 {
35- return fmt .Errorf ("Put method expected 3 arguments got %d\n " , len (nonFlagArgs ))
33+ return fmt .Errorf ("put method expected 3 arguments got %d" , len (nonFlagArgs ))
3634 }
3735 sourceFilePath , dst := nonFlagArgs [1 ], nonFlagArgs [2 ]
3836
@@ -44,29 +42,29 @@ func (sty *Strategy) ExecuteCommand(cmd string, nonFlagArgs []string) error {
4442
4543 case "get" :
4644 if len (nonFlagArgs ) != 3 {
47- return fmt .Errorf ("Get method expected 3 arguments got %d\n " , len (nonFlagArgs ))
45+ return fmt .Errorf ("get method expected 3 arguments got %d" , len (nonFlagArgs ))
4846 }
4947 src , dst := nonFlagArgs [1 ], nonFlagArgs [2 ]
5048 return sty .str .Get (src , dst )
5149
5250 case "copy" :
5351 if len (nonFlagArgs ) != 3 {
54- return fmt .Errorf ("Copy method expected 3 arguments got %d\n " , len (nonFlagArgs ))
52+ return fmt .Errorf ("copy method expected 3 arguments got %d" , len (nonFlagArgs ))
5553 }
5654
5755 srcBlob , dstBlob := nonFlagArgs [1 ], nonFlagArgs [2 ]
5856 return sty .str .Copy (srcBlob , dstBlob )
5957
6058 case "delete" :
6159 if len (nonFlagArgs ) != 2 {
62- return fmt .Errorf ("Delete method expected 2 arguments got %d\n " , len (nonFlagArgs ))
60+ return fmt .Errorf ("delete method expected 2 arguments got %d" , len (nonFlagArgs ))
6361 }
6462 return sty .str .Delete (nonFlagArgs [1 ])
6563
6664 case "delete-recursive" :
6765 var prefix string
6866 if len (nonFlagArgs ) > 2 {
69- return fmt .Errorf ("delete-recursive takes at most one argument (prefix) got %d\n " , len (nonFlagArgs )- 1 )
67+ return fmt .Errorf ("delete-recursive takes at most one argument (prefix) got %d" , len (nonFlagArgs )- 1 )
7068 } else if len (nonFlagArgs ) == 2 {
7169 prefix = nonFlagArgs [1 ]
7270 } else {
@@ -76,36 +74,36 @@ func (sty *Strategy) ExecuteCommand(cmd string, nonFlagArgs []string) error {
7674
7775 case "exists" :
7876 if len (nonFlagArgs ) != 2 {
79- return fmt .Errorf ("Exists method expected 2 arguments got %d\n " , len (nonFlagArgs ))
77+ return fmt .Errorf ("exists method expected 2 arguments got %d" , len (nonFlagArgs ))
8078 }
8179
8280 exists , err := sty .str .Exists (nonFlagArgs [1 ])
8381 if err == nil && ! exists {
8482 return & NotExistsError {}
8583 }
8684 if err != nil {
87- return fmt .Errorf ("Failed to check exist: %w" , err )
85+ return fmt .Errorf ("failed to check exist: %w" , err )
8886 }
8987
9088 case "sign" :
9189 if len (nonFlagArgs ) != 4 {
92- return fmt .Errorf ("Sign method expects 3 arguments got %d\n " , len (nonFlagArgs )- 1 )
90+ return fmt .Errorf ("sign method expects 3 arguments got %d" , len (nonFlagArgs )- 1 )
9391 }
9492
9593 objectID , action := nonFlagArgs [1 ], nonFlagArgs [2 ]
9694 action = strings .ToLower (action )
9795 if action != "get" && action != "put" {
98- return fmt .Errorf ("Action not implemented: %s. Available actions are 'get' and 'put'" , action )
96+ return fmt .Errorf ("action not implemented: %s. Available actions are 'get' and 'put'" , action )
9997 }
10098
10199 expiration , err := time .ParseDuration (nonFlagArgs [3 ])
102100 if err != nil {
103- return fmt .Errorf ("Expiration should be in the format of a duration i.e. 1h, 60m, 3600s. Got: %s" , nonFlagArgs [3 ])
101+ return fmt .Errorf ("expiration should be in the format of a duration i.e. 1h, 60m, 3600s. Got: %s" , nonFlagArgs [3 ])
104102 }
105103
106104 signedURL , err := sty .str .Sign (objectID , action , expiration )
107105 if err != nil {
108- return fmt .Errorf ("Failed to sign request: %w" , err )
106+ return fmt .Errorf ("failed to sign request: %w" , err )
109107 }
110108 fmt .Print (signedURL )
111109
@@ -117,13 +115,13 @@ func (sty *Strategy) ExecuteCommand(cmd string, nonFlagArgs []string) error {
117115 } else if len (nonFlagArgs ) == 2 {
118116 prefix = nonFlagArgs [1 ]
119117 } else {
120- return fmt .Errorf ("List method expected 1 or 2 arguments, got %d\n " , len (nonFlagArgs )- 1 )
118+ return fmt .Errorf ("list method expected 1 or 2 arguments, got %d" , len (nonFlagArgs )- 1 )
121119 }
122120
123121 var objects []string
124122 objects , err := sty .str .List (prefix )
125123 if err != nil {
126- return fmt .Errorf ("Failed to list objects: %w" , err )
124+ return fmt .Errorf ("failed to list objects: %w" , err )
127125 }
128126
129127 for _ , object := range objects {
@@ -132,18 +130,18 @@ func (sty *Strategy) ExecuteCommand(cmd string, nonFlagArgs []string) error {
132130
133131 case "properties" :
134132 if len (nonFlagArgs ) != 2 {
135- return fmt .Errorf ("Properties method expected 2 arguments got %d\n " , len (nonFlagArgs ))
133+ return fmt .Errorf ("properties method expected 2 arguments got %d" , len (nonFlagArgs ))
136134 }
137135 return sty .str .Properties (nonFlagArgs [1 ])
138136
139137 case "ensure-storage-exists" :
140138 if len (nonFlagArgs ) != 1 {
141- return fmt .Errorf ("EnsureStorageExists method expected 1 arguments got %d\n " , len (nonFlagArgs ))
139+ return fmt .Errorf ("ensureStorageExists method expected 1 arguments got %d" , len (nonFlagArgs ))
142140 }
143141 return sty .str .EnsureStorageExists ()
144142
145143 default :
146- return fmt .Errorf ("unknown command: '%s'\n " , cmd )
144+ return fmt .Errorf ("unknown command: '%s'" , cmd )
147145 }
148146
149147 return nil
0 commit comments