5
5
package cli
6
6
7
7
import (
8
- "fmt"
9
- "os"
10
- "text/tabwriter"
11
- "time"
12
-
13
- log "github.com/scaleway/scaleway-cli/vendor/github.com/Sirupsen/logrus"
14
- "github.com/scaleway/scaleway-cli/vendor/github.com/docker/docker/pkg/units"
15
-
16
- utils "github.com/scaleway/scaleway-cli/pkg/utils"
8
+ "github.com/Sirupsen/logrus"
9
+ "github.com/scaleway/scaleway-cli/pkg/commands"
17
10
)
18
11
19
12
var cmdHistory = & Command {
@@ -34,39 +27,22 @@ var historyNoTrunc bool // --no-trunc flag
34
27
var historyQuiet bool // -q, --quiet flag
35
28
var historyHelp bool // -h, --help flag
36
29
37
- func runHistory (cmd * Command , args []string ) {
30
+ func runHistory (cmd * Command , rawArgs []string ) {
38
31
if historyHelp {
39
32
cmd .PrintUsage ()
40
33
}
41
- if len (args ) != 1 {
34
+ if len (rawArgs ) != 1 {
42
35
cmd .PrintShortUsage ()
43
36
}
44
37
45
- imageID := cmd .API .GetImageID (args [0 ], true )
46
- image , err := cmd .API .GetImage (imageID )
47
- if err != nil {
48
- log .Fatalf ("Cannot get image %s: %v" , imageID , err )
49
- }
50
-
51
- if imagesQ {
52
- fmt .Println (imageID )
53
- return
38
+ args := commands.HistoryArgs {
39
+ Quiet : historyQuiet ,
40
+ NoTrunc : historyNoTrunc ,
41
+ Image : rawArgs [0 ],
54
42
}
55
-
56
- w := tabwriter .NewWriter (os .Stdout , 10 , 1 , 3 , ' ' , 0 )
57
- defer w .Flush ()
58
- fmt .Fprintf (w , "IMAGE\t CREATED\t CREATED BY\t SIZE\n " )
59
-
60
- identifier := utils .TruncIf (image .Identifier , 8 , ! historyNoTrunc )
61
-
62
- creationDate , err := time .Parse ("2006-01-02T15:04:05.000000+00:00" , image .CreationDate )
43
+ ctx := cmd .GetContext (rawArgs )
44
+ err := commands .RunHistory (ctx , args )
63
45
if err != nil {
64
- log .Fatalf ("Unable to parse creation date from the Scaleway API : %v" , err )
46
+ logrus .Fatalf ("Cannot execute 'history' : %v" , err )
65
47
}
66
- creationDateStr := units .HumanDuration (time .Now ().UTC ().Sub (creationDate ))
67
-
68
- volumeName := utils .TruncIf (image .RootVolume .Name , 25 , ! historyNoTrunc )
69
- size := units .HumanSize (float64 (image .RootVolume .Size ))
70
-
71
- fmt .Fprintf (w , "%s\t %s\t %s\t %s\n " , identifier , creationDateStr , volumeName , size )
72
48
}
0 commit comments