-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add _cs #222
Add _cs #222
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -631,6 +631,26 @@ type ScalewayTokensDefinition struct { | |
Token ScalewayTokenDefinition `json:"token"` | ||
} | ||
|
||
type ScalewayContainerData struct { | ||
LastModified string `json:"last_modified"` | ||
Name string `json:"name"` | ||
Size string `json:"size"` | ||
} | ||
|
||
type ScalewayGetContainerDatas struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exported type ScalewayGetContainerDatas should have comment or be unexported |
||
Container []ScalewayContainerData `json:"container"` | ||
} | ||
|
||
type ScalewayContainer struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exported type ScalewayContainer should have comment or be unexported |
||
ScalewayOrganizationDefinition `json:"organization"` | ||
Name string `json:"name"` | ||
Size string `json:"size"` | ||
} | ||
|
||
type ScalewayGetContainers struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exported type ScalewayGetContainers should have comment or be unexported |
||
Containers []ScalewayContainer `json:"containers"` | ||
} | ||
|
||
// ScalewayConnectResponse represents the answer from POST /tokens | ||
type ScalewayConnectResponse struct { | ||
Token ScalewayTokenDefinition `json:"token"` | ||
|
@@ -1861,6 +1881,46 @@ func (s *ScalewayAPI) GetASecurityGroup(groupsID string) (*ScalewayGetSecurityGr | |
return &securityGroups, nil | ||
} | ||
|
||
// GetContainers returns a ScalewayGetContainers | ||
func (s *ScalewayAPI) GetContainers() (*ScalewayGetContainers, error) { | ||
resp, err := s.GetResponse("containers") | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer resp.Body.Close() | ||
|
||
body, err := s.handleHTTPError([]int{200}, resp) | ||
if err != nil { | ||
return nil, err | ||
} | ||
var containers ScalewayGetContainers | ||
|
||
if err = json.Unmarshal(body, &containers); err != nil { | ||
return nil, err | ||
} | ||
return &containers, nil | ||
} | ||
|
||
// GetContainerDatas returns a ScalewayGetContainerDatas | ||
func (s *ScalewayAPI) GetContainerDatas(container string) (*ScalewayGetContainerDatas, error) { | ||
resp, err := s.GetResponse(fmt.Sprintf("containers/%s", container)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer resp.Body.Close() | ||
|
||
body, err := s.handleHTTPError([]int{200}, resp) | ||
if err != nil { | ||
return nil, err | ||
} | ||
var datas ScalewayGetContainerDatas | ||
|
||
if err = json.Unmarshal(body, &datas); err != nil { | ||
return nil, err | ||
} | ||
return &datas, nil | ||
} | ||
|
||
// GetIPS returns a ScalewayGetIPS | ||
func (s *ScalewayAPI) GetIPS() (*ScalewayGetIPS, error) { | ||
resp, err := s.GetResponse("ips") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,4 +47,5 @@ var Commands = []*Command{ | |
cmdPatch, | ||
cmdSecurityGroups, | ||
cmdIPS, | ||
cmdCS, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright (C) 2015 Scaleway. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE.md file. | ||
|
||
package cli | ||
|
||
import "fmt" | ||
|
||
var cmdCS = &Command{ | ||
Exec: runCS, | ||
UsageLine: "_cs [CONTAINER_NAME]", | ||
Description: "", | ||
Hidden: true, | ||
Help: "List containers / datas", | ||
Examples: ` | ||
$ scw _cs | ||
$ scw _cs containerName | ||
`, | ||
} | ||
|
||
func init() { | ||
cmdCS.Flag.BoolVar(&csHelp, []string{"h", "-help"}, false, "Print usage") | ||
} | ||
|
||
// Flags | ||
var csHelp bool // -h, --help flag | ||
|
||
func runCS(cmd *Command, args []string) error { | ||
if csHelp { | ||
return cmd.PrintUsage() | ||
} | ||
if len(args) > 1 { | ||
return cmd.PrintShortUsage() | ||
} | ||
if len(args) == 0 { | ||
containers, err := cmd.API.GetContainers() | ||
if err != nil { | ||
return fmt.Errorf("Unable to get your containers: %v", err) | ||
} | ||
printRawMode(cmd.Streams().Stdout, *containers) | ||
return nil | ||
} | ||
datas, err := cmd.API.GetContainerDatas(args[0]) | ||
if err != nil { | ||
return fmt.Errorf("Unable to get your data from %s: %v", args[1], err) | ||
} | ||
printRawMode(cmd.Streams().Stdout, *datas) | ||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported type ScalewayContainerData should have comment or be unexported