Skip to content

Commit 6e7544e

Browse files
author
Quentin Perez
committed
Improve _cs format
1 parent 706981e commit 6e7544e

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,7 @@ $ scw inspect myserver | jq '.[0].public_ip.address'
11321132

11331133
### master (unreleased)
11341134

1135+
* Improve _cs format ([#223](https://github.com/scaleway/scaleway-cli/issues/223))
11351136
* Use `gotty-client` instead of `termjs-cli`
11361137
* Fix: bad detection of server already started when starting a server ([#224](https://github.com/scaleway/scaleway-cli/pull/224)) - [@arianvp](https://github.com/arianvp)
11371138
* Added _cs ([#180](https://github.com/scaleway/scaleway-cli/issues/180))

pkg/cli/x_cs.go

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@
44

55
package cli
66

7-
import "fmt"
7+
import (
8+
"fmt"
9+
"strconv"
10+
"strings"
11+
"time"
12+
13+
"github.com/scaleway/scaleway-cli/vendor/github.com/dustin/go-humanize"
14+
)
815

916
var cmdCS = &Command{
1017
Exec: runCS,
@@ -37,13 +44,28 @@ func runCS(cmd *Command, args []string) error {
3744
if err != nil {
3845
return fmt.Errorf("Unable to get your containers: %v", err)
3946
}
40-
printRawMode(cmd.Streams().Stdout, *containers)
47+
for _, container := range containers.Containers {
48+
fmt.Fprintf(cmd.Streams().Stdout, "s3://%s\n", container.Name)
49+
}
4150
return nil
4251
}
43-
datas, err := cmd.API.GetContainerDatas(args[0])
52+
container := strings.Replace(args[0], "s3://", "", 1)
53+
datas, err := cmd.API.GetContainerDatas(container)
4454
if err != nil {
45-
return fmt.Errorf("Unable to get your data from %s: %v", args[1], err)
55+
return fmt.Errorf("Unable to get your data from %s: %v", container, err)
56+
}
57+
for _, data := range datas.Container {
58+
t, err := time.Parse(time.RFC3339, data.LastModified)
59+
if err != nil {
60+
return err
61+
}
62+
year, month, day := t.Date()
63+
hour, minute, _ := t.Clock()
64+
size, err := strconv.Atoi(data.Size)
65+
if err != nil {
66+
return err
67+
}
68+
fmt.Fprintf(cmd.Streams().Stdout, "%-4d-%02d-%02d %02d:%02d %8s s3://%s/%s\n", year, month, day, hour, minute, humanize.Bytes(uint64(size)), container, data.Name)
4669
}
47-
printRawMode(cmd.Streams().Stdout, *datas)
4870
return nil
4971
}

0 commit comments

Comments
 (0)