Skip to content

Commit 7b0ad4e

Browse files
committed
Add _cs command
1 parent a8b1dbf commit 7b0ad4e

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

README.md

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

11321132
### master (unreleased)
11331133

1134+
* Added _cs ([#180](https://github.com/scaleway/scaleway-cli/issues/180))
11341135
* Added SCALEWAY_VERBOSE_API to make the API more verbose
11351136
* Support of 'scw _ips' command ... ([#196](https://github.com/scaleway/scaleway-cli/issues/196))
11361137
* Report **permissions** in `scw info` ([#191](https://github.com/scaleway/scaleway-cli/issues/191))

pkg/cli/commands.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,5 @@ var Commands = []*Command{
4747
cmdPatch,
4848
cmdSecurityGroups,
4949
cmdIPS,
50+
cmdCS,
5051
}

pkg/cli/x_cs.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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 cli
6+
7+
import "fmt"
8+
9+
var cmdCS = &Command{
10+
Exec: runCS,
11+
UsageLine: "_cs [CONTAINER_NAME]",
12+
Description: "",
13+
Hidden: true,
14+
Help: "List containers / datas",
15+
Examples: `
16+
$ scw _cs
17+
$ scw _cs containerName
18+
`,
19+
}
20+
21+
func init() {
22+
cmdCS.Flag.BoolVar(&csHelp, []string{"h", "-help"}, false, "Print usage")
23+
}
24+
25+
// Flags
26+
var csHelp bool // -h, --help flag
27+
28+
func runCS(cmd *Command, args []string) error {
29+
if csHelp {
30+
return cmd.PrintUsage()
31+
}
32+
if len(args) > 1 {
33+
return cmd.PrintShortUsage()
34+
}
35+
if len(args) == 0 {
36+
containers, err := cmd.API.GetContainers()
37+
if err != nil {
38+
return fmt.Errorf("Unable to get your containers: %v", err)
39+
}
40+
printRawMode(cmd.Streams().Stdout, *containers)
41+
return nil
42+
}
43+
datas, err := cmd.API.GetContainerDatas(args[0])
44+
if err != nil {
45+
return fmt.Errorf("Unable to get your data from %s: %v", args[1], err)
46+
}
47+
printRawMode(cmd.Streams().Stdout, *datas)
48+
return nil
49+
}

0 commit comments

Comments
 (0)