本文整理汇总了Golang中github.com/scaleway/scaleway-cli/commands/types.Command.PrintShortUsage方法的典型用法代码示例。如果您正苦于以下问题:Golang Command.PrintShortUsage方法的具体用法?Golang Command.PrintShortUsage怎么用?Golang Command.PrintShortUsage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/scaleway/scaleway-cli/commands/types.Command
的用法示例。
在下文中一共展示了Command.PrintShortUsage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: runInfo
func runInfo(cmd *types.Command, args []string) {
if infoHelp {
cmd.PrintUsage()
}
if len(args) != 0 {
cmd.PrintShortUsage()
}
// FIXME: fmt.Printf("Servers: %s\n", "quantity")
// FIXME: fmt.Printf("Images: %s\n", "quantity")
fmt.Printf("Debug mode (client): %v\n", os.Getenv("DEBUG") != "")
fmt.Printf("Organization: %s\n", cmd.API.Organization)
// FIXME: add partially-masked token
fmt.Printf("API Endpoint: %s\n", os.Getenv("scaleway_api_endpoint"))
configPath, _ := utils.GetConfigFilePath()
fmt.Printf("RC file: %s\n", configPath)
fmt.Printf("User: %s\n", os.Getenv("USER"))
fmt.Printf("CPUs: %d\n", runtime.NumCPU())
hostname, _ := os.Hostname()
fmt.Printf("Hostname: %s\n", hostname)
cliPath, _ := osext.Executable()
fmt.Printf("CLI Path: %s\n", cliPath)
fmt.Printf("Cache: %s\n", cmd.API.Cache.Path)
fmt.Printf(" Servers: %d\n", cmd.API.Cache.GetNbServers())
fmt.Printf(" Images: %d\n", cmd.API.Cache.GetNbImages())
fmt.Printf(" Snapshots: %d\n", cmd.API.Cache.GetNbSnapshots())
fmt.Printf(" Volumes: %d\n", cmd.API.Cache.GetNbVolumes())
fmt.Printf(" Bootscripts: %d\n", cmd.API.Cache.GetNbBootscripts())
}
示例2: runCompletion
func runCompletion(cmd *types.Command, args []string) {
if completionHelp {
cmd.PrintUsage()
}
if len(args) != 1 {
cmd.PrintShortUsage()
}
category := args[0]
elements := []string{}
switch category {
case "servers-all":
for identifier, name := range cmd.API.Cache.Servers {
elements = append(elements, identifier, wordifyName(name, "server"))
}
case "servers-names":
for _, name := range cmd.API.Cache.Servers {
elements = append(elements, wordifyName(name, "server"))
}
case "images-all":
for identifier, name := range cmd.API.Cache.Images {
elements = append(elements, identifier, wordifyName(name, "image"))
}
case "images-names":
for _, name := range cmd.API.Cache.Images {
elements = append(elements, wordifyName(name, "image"))
}
case "volumes-all":
for identifier, name := range cmd.API.Cache.Volumes {
elements = append(elements, identifier, wordifyName(name, "volume"))
}
case "volumes-names":
for _, name := range cmd.API.Cache.Volumes {
elements = append(elements, wordifyName(name, "volume"))
}
case "snapshots-all":
for identifier, name := range cmd.API.Cache.Snapshots {
elements = append(elements, identifier, wordifyName(name, "snapshot"))
}
case "snapshots-names":
for _, name := range cmd.API.Cache.Snapshots {
elements = append(elements, wordifyName(name, "snapshot"))
}
case "bootscripts-all":
for identifier, name := range cmd.API.Cache.Bootscripts {
elements = append(elements, identifier, wordifyName(name, "bootscript"))
}
case "bootscripts-names":
for _, name := range cmd.API.Cache.Bootscripts {
elements = append(elements, wordifyName(name, "bootscript"))
}
default:
log.Fatalf("Unhandled category of completion: %s", category)
}
sort.Strings(elements)
fmt.Println(strings.Join(utils.RemoveDuplicates(elements), "\n"))
}
示例3: runCommit
func runCommit(cmd *types.Command, args []string) {
if commitHelp {
cmd.PrintUsage()
}
if len(args) < 1 {
cmd.PrintShortUsage()
}
serverID := cmd.API.GetServerID(args[0])
server, err := cmd.API.GetServer(serverID)
if err != nil {
log.Fatalf("Cannot fetch server: %v", err)
}
var volume = server.Volumes[fmt.Sprintf("%d", commitVolume)]
var name string
if len(args) > 1 {
name = args[1]
} else {
name = volume.Name + "-snapshot"
}
snapshot, err := cmd.API.PostSnapshot(volume.Identifier, name)
if err != nil {
log.Fatalf("Cannot create snapshot: %v", err)
}
fmt.Println(snapshot)
}
示例4: runRestart
func runRestart(cmd *types.Command, args []string) {
if restartHelp {
cmd.PrintUsage()
}
if len(args) < 1 {
cmd.PrintShortUsage()
}
hasError := false
for _, needle := range args {
server := cmd.API.GetServerID(needle)
err := cmd.API.PostServerAction(server, "reboot")
if err != nil {
if err.Error() != "server is being stopped or rebooted" {
log.Errorf("failed to restart server %s: %s", server, err)
hasError = true
}
} else {
fmt.Println(needle)
}
if hasError {
os.Exit(1)
}
}
}
示例5: runPatch
func runPatch(cmd *types.Command, args []string) {
if patchHelp {
cmd.PrintUsage()
}
if len(args) != 2 {
cmd.PrintShortUsage()
}
// Parsing FIELD=VALUE
updateParts := strings.Split(args[1], "=")
if len(updateParts) != 2 {
cmd.PrintShortUsage()
}
fieldName := updateParts[0]
newValue := updateParts[1]
changes := 0
ident := api.GetIdentifier(cmd.API, args[0])
switch ident.Type {
case api.IdentifierServer:
currentServer, err := cmd.API.GetServer(ident.Identifier)
if err != nil {
log.Fatalf("Cannot get server %s: %v", ident.Identifier, err)
}
var payload api.ScalewayServerPatchDefinition
switch fieldName {
case "state_detail":
log.Debugf("%s=%s => %s=%s", fieldName, currentServer.StateDetail, fieldName, newValue)
if currentServer.StateDetail != newValue {
changes++
payload.StateDetail = &newValue
}
case "name":
log.Warnf("To rename a server, Use 'scw rename'")
log.Debugf("%s=%s => %s=%s", fieldName, currentServer.StateDetail, fieldName, newValue)
if currentServer.Name != newValue {
changes++
payload.Name = &newValue
}
default:
log.Fatalf("'_patch server %s=' not implemented", fieldName)
}
if changes > 0 {
log.Debugf("updating server: %d change(s)", changes)
err = cmd.API.PatchServer(ident.Identifier, payload)
} else {
log.Debugf("no changes, not updating server")
}
if err != nil {
log.Fatalf("Cannot rename server: %v", err)
}
default:
log.Fatalf("_patch not implemented for this kind of object")
}
fmt.Println(ident.Identifier)
}
示例6: runRun
func runRun(cmd *types.Command, args []string) {
if runHelpFlag {
cmd.PrintUsage()
}
if len(args) < 1 {
cmd.PrintShortUsage()
}
if runAttachFlag && len(args) > 1 {
log.Fatalf("Cannot use '--attach' and 'COMMAND [ARG...]' at the same time. See 'scw run --help'")
}
// create IMAGE
log.Debugf("Creating a new server")
serverID, err := api.CreateServer(cmd.API, args[0], runCreateName, runCreateBootscript, runCreateEnv, runCreateVolume)
if err != nil {
log.Fatalf("Failed to create server: %v", err)
}
log.Debugf("Created server: %s", serverID)
// start SERVER
log.Debugf("Starting server")
err = api.StartServer(cmd.API, serverID, false)
if err != nil {
log.Fatalf("Failed to start server %s: %v", serverID, err)
}
log.Debugf("Server is booting")
if runAttachFlag {
// Attach to server serial
log.Debugf("Attaching to server console")
err = utils.AttachToSerial(serverID, cmd.API.Token, true)
if err != nil {
log.Fatalf("Cannot attach to server serial: %v", err)
}
} else {
// waiting for server to be ready
log.Debugf("Waiting for server to be ready")
// We wait for 30 seconds, which is the minimal amount of time needed by a server to boot
time.Sleep(30 * time.Second)
server, err := api.WaitForServerReady(cmd.API, serverID)
if err != nil {
log.Fatalf("Cannot get access to server %s: %v", serverID, err)
}
log.Debugf("Server is ready: %s", server.PublicAddress.IP)
// exec -w SERVER COMMAND ARGS...
log.Debugf("Executing command")
if len(args) < 2 {
err = utils.SSHExec(server.PublicAddress.IP, []string{"if [ -x /bin/bash ]; then exec /bin/bash; else exec /bin/sh; fi"}, false)
} else {
err = utils.SSHExec(server.PublicAddress.IP, args[1:], false)
}
if err != nil {
log.Debugf("Command execution failed: %v", err)
os.Exit(1)
}
log.Debugf("Command successfuly executed")
}
}
示例7: runInspect
func runInspect(cmd *types.Command, args []string) {
if inspectHelp {
cmd.PrintUsage()
}
if len(args) < 1 {
cmd.PrintShortUsage()
}
res := "["
nbInspected := 0
ci := make(chan api.ScalewayResolvedIdentifier)
cj := make(chan interface{})
go api.ResolveIdentifiers(cmd.API, args, ci)
go api.InspectIdentifiers(cmd.API, ci, cj)
for {
data, open := <-cj
if !open {
break
}
if inspectFormat == "" {
dataB, err := json.MarshalIndent(data, "", " ")
if err == nil {
if nbInspected != 0 {
res += ",\n"
}
res += string(dataB)
nbInspected++
}
} else {
tmpl, err := template.New("").Funcs(api.FuncMap).Parse(inspectFormat)
if err != nil {
log.Fatalf("Format parsing error: %v", err)
}
err = tmpl.Execute(os.Stdout, data)
if err != nil {
log.Fatalf("Format execution error: %v", err)
}
fmt.Fprint(os.Stdout, "\n")
nbInspected++
}
}
res += "]"
if inspectFormat == "" {
if os.Getenv("SCW_SENSITIVE") != "1" {
res = cmd.API.HideApiCredentials(res)
}
fmt.Println(res)
}
if len(args) != nbInspected {
os.Exit(1)
}
}
示例8: runLogin
func runLogin(cmd *types.Command, args []string) {
if loginHelp {
cmd.PrintUsage()
}
if len(args) != 0 {
cmd.PrintShortUsage()
}
if len(organization) == 0 {
fmt.Println("You can get your credentials on https://cloud.scaleway.com/#/credentials")
promptUser("Organization (access key): ", &organization, true)
}
if len(token) == 0 {
promptUser("Token: ", &token, false)
}
cfg := &api.Config{
APIEndPoint: "https://account.scaleway.com/",
Organization: strings.Trim(organization, "\n"),
Token: strings.Trim(token, "\n"),
}
api, err := api.NewScalewayAPI(cfg.APIEndPoint, cfg.Organization, cfg.Token)
if err != nil {
log.Fatalf("Unable to create ScalewayAPI: %s", err)
}
err = api.CheckCredentials()
if err != nil {
log.Fatalf("Unable to contact ScalewayAPI: %s", err)
}
scwrcPath, err := utils.GetConfigFilePath()
if err != nil {
log.Fatalf("Unable to get scwrc config file path: %s", err)
}
scwrc, err := os.OpenFile(scwrcPath, os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0600)
if err != nil {
log.Fatalf("Unable to create scwrc config file: %s", err)
}
defer scwrc.Close()
encoder := json.NewEncoder(scwrc)
cfg.APIEndPoint = "https://api.scaleway.com/"
err = encoder.Encode(cfg)
if err != nil {
log.Fatalf("Unable to encode scw config file: %s", err)
}
}
示例9: runStart
func runStart(cmd *types.Command, args []string) {
if startHelp {
cmd.PrintUsage()
}
if len(args) < 1 {
cmd.PrintShortUsage()
}
hasError := false
errChan := make(chan error)
successChan := make(chan bool)
remainingItems := len(args)
for i := range args {
needle := args[i]
go api.StartServerOnce(cmd.API, needle, startW, successChan, errChan)
}
if startTimeout > 0 {
go func() {
time.Sleep(time.Duration(startTimeout*1000) * time.Millisecond)
log.Fatalf("Operation timed out")
}()
}
for {
select {
case _ = <-successChan:
remainingItems--
case err := <-errChan:
log.Errorf(fmt.Sprintf("%s", err))
remainingItems--
hasError = true
}
if remainingItems == 0 {
break
}
}
if hasError {
os.Exit(1)
}
}
示例10: runPort
func runPort(cmd *types.Command, args []string) {
if portHelp {
cmd.PrintUsage()
}
if len(args) < 1 {
cmd.PrintShortUsage()
}
serverID := cmd.API.GetServerID(args[0])
server, err := cmd.API.GetServer(serverID)
if err != nil {
log.Fatalf("Failed to get server information for %s: %v", serverID, err)
}
command := []string{"netstat -lutn 2>/dev/null | grep LISTEN"}
err = utils.SSHExec(server.PublicAddress.IP, command, true)
if err != nil {
log.Fatalf("Command execution failed: %v", err)
}
}
示例11: runTag
func runTag(cmd *types.Command, args []string) {
if tagHelp {
cmd.PrintUsage()
}
if len(args) != 2 {
cmd.PrintShortUsage()
}
snapshotID := cmd.API.GetSnapshotID(args[0])
snapshot, err := cmd.API.GetSnapshot(snapshotID)
if err != nil {
log.Fatalf("Cannot fetch snapshot: %v", err)
}
image, err := cmd.API.PostImage(snapshot.Identifier, args[1])
if err != nil {
log.Fatalf("Cannot create image: %v", err)
}
fmt.Println(image)
}
示例12: runRename
func runRename(cmd *types.Command, args []string) {
if renameHelp {
cmd.PrintUsage()
}
if len(args) != 2 {
cmd.PrintShortUsage()
}
serverID := cmd.API.GetServerID(args[0])
var server api.ScalewayServerPatchDefinition
server.Name = &args[1]
err := cmd.API.PatchServer(serverID, server)
if err != nil {
log.Fatalf("Cannot rename server: %v", err)
} else {
cmd.API.Cache.InsertServer(serverID, *server.Name)
}
}
示例13: runExec
func runExec(cmd *types.Command, args []string) {
if execHelp {
cmd.PrintUsage()
}
if len(args) < 2 {
cmd.PrintShortUsage()
}
serverID := cmd.API.GetServerID(args[0])
var server *api.ScalewayServer
var err error
if execW {
// --wait
server, err = api.WaitForServerReady(cmd.API, serverID)
if err != nil {
log.Fatalf("Failed to wait for server to be ready, %v", err)
}
} else {
// no --wait
server, err = cmd.API.GetServer(serverID)
if err != nil {
log.Fatalf("Failed to get server information for %s: %v", serverID, err)
}
}
if execTimeout > 0 {
go func() {
time.Sleep(time.Duration(execTimeout*1000) * time.Millisecond)
log.Fatalf("Operation timed out")
}()
}
err = utils.SSHExec(server.PublicAddress.IP, args[1:], !execW)
if err != nil {
log.Fatalf("%v", err)
os.Exit(1)
}
log.Debugf("Command successfuly executed")
}
示例14: runLogs
func runLogs(cmd *types.Command, args []string) {
if logsHelp {
cmd.PrintUsage()
}
if len(args) != 1 {
cmd.PrintShortUsage()
}
serverID := cmd.API.GetServerID(args[0])
server, err := cmd.API.GetServer(serverID)
if err != nil {
log.Fatalf("Failed to get server information for %s: %v", serverID, err)
}
// FIXME: switch to serial history when API is ready
command := []string{"dmesg"}
err = utils.SSHExec(server.PublicAddress.IP, command, true)
if err != nil {
log.Fatalf("Command execution failed: %v", err)
}
}
示例15: runCp
func runCp(cmd *types.Command, args []string) {
if cpHelp {
cmd.PrintUsage()
}
if len(args) != 2 {
cmd.PrintShortUsage()
}
if strings.Count(args[0], ":") > 1 || strings.Count(args[1], ":") > 1 {
log.Fatalf("usage: scw %s", cmd.UsageLine)
}
sourceStream, err := TarFromSource(cmd.API, args[0])
if err != nil {
log.Fatalf("Cannot tar from source '%s': %v", args[0], err)
}
err = UntarToDest(cmd.API, sourceStream, args[1])
if err != nil {
log.Fatalf("Cannot untar to destination '%s': %v", args[1], err)
}
}