File tree 2 files changed +39
-13
lines changed
2 files changed +39
-13
lines changed Original file line number Diff line number Diff line change 5
5
package cli
6
6
7
7
import (
8
- "fmt"
9
-
10
- log "github.com/scaleway/scaleway-cli/vendor/github.com/Sirupsen/logrus"
8
+ "github.com/scaleway/scaleway-cli/pkg/commands"
9
+ "github.com/scaleway/scaleway-cli/vendor/github.com/Sirupsen/logrus"
11
10
)
12
11
13
12
var cmdTag = & Command {
@@ -24,23 +23,21 @@ func init() {
24
23
// Flags
25
24
var tagHelp bool // -h, --help flag
26
25
27
- func runTag (cmd * Command , args []string ) {
26
+ func runTag (cmd * Command , rawArgs []string ) {
28
27
if tagHelp {
29
28
cmd .PrintUsage ()
30
29
}
31
- if len (args ) != 2 {
30
+ if len (rawArgs ) != 2 {
32
31
cmd .PrintShortUsage ()
33
32
}
34
33
35
- snapshotID := cmd .API .GetSnapshotID (args [0 ])
36
- snapshot , err := cmd .API .GetSnapshot (snapshotID )
37
- if err != nil {
38
- log .Fatalf ("Cannot fetch snapshot: %v" , err )
34
+ args := commands.TagArgs {
35
+ Snapshot : rawArgs [0 ],
36
+ Name : rawArgs [1 ],
39
37
}
40
-
41
- image , err := cmd . API . PostImage ( snapshot . Identifier , args [ 1 ] )
38
+ ctx := cmd . GetContext ( rawArgs )
39
+ err := commands . RunTag ( ctx , args )
42
40
if err != nil {
43
- log .Fatalf ("Cannot create image : %v" , err )
41
+ logrus .Fatalf ("Cannot execute 'tag' : %v" , err )
44
42
}
45
- fmt .Println (image )
46
43
}
Original file line number Diff line number Diff line change
1
+ // Copyright (C) 2015 Scaleway. All rights reserved.
2
+ // Use of this source code is governed by a MIT-style
3
+ // license that can be found in the LICENSE.md file.
4
+
5
+ package commands
6
+
7
+ import "fmt"
8
+
9
+ // TagArgs are flags for the `RunTag` function
10
+ type TagArgs struct {
11
+ Snapshot string
12
+ Name string
13
+ }
14
+
15
+ // RunTag is the handler for 'scw tag'
16
+ func RunTag (ctx CommandContext , args TagArgs ) error {
17
+ snapshotID := ctx .API .GetSnapshotID (args .Snapshot )
18
+ snapshot , err := ctx .API .GetSnapshot (snapshotID )
19
+ if err != nil {
20
+ return fmt .Errorf ("cannot fetch snapshot: %v" , err )
21
+ }
22
+
23
+ image , err := ctx .API .PostImage (snapshot .Identifier , args .Name )
24
+ if err != nil {
25
+ return fmt .Errorf ("cannot create image: %v" , err )
26
+ }
27
+ fmt .Fprintln (ctx .Stdout , image )
28
+ return nil
29
+ }
You can’t perform that action at this time.
0 commit comments