(cmd *cobra.Command, args []string)
| 52 | } |
| 53 | |
| 54 | func getVarRun(cmd *cobra.Command, args []string) error { |
| 55 | defer func() { |
| 56 | sendActivity("getvar", WshExitCode == 0) |
| 57 | }() |
| 58 | |
| 59 | // Resolve block to get zoneId |
| 60 | if blockArg == "" { |
| 61 | if getVarLocal { |
| 62 | blockArg = "this" |
| 63 | } else { |
| 64 | blockArg = "client" |
| 65 | } |
| 66 | } |
| 67 | fullORef, err := resolveBlockArg() |
| 68 | if err != nil { |
| 69 | return err |
| 70 | } |
| 71 | |
| 72 | if getVarAllVars { |
| 73 | if len(args) > 0 { |
| 74 | return fmt.Errorf("cannot specify key with --all") |
| 75 | } |
| 76 | return getAllVariables(fullORef.OID) |
| 77 | } |
| 78 | |
| 79 | // Single variable case - existing logic |
| 80 | if len(args) != 1 { |
| 81 | OutputHelpMessage(cmd) |
| 82 | return fmt.Errorf("requires a key argument") |
| 83 | } |
| 84 | |
| 85 | key := args[0] |
| 86 | commandData := wshrpc.CommandVarData{ |
| 87 | Key: key, |
| 88 | ZoneId: fullORef.OID, |
| 89 | FileName: getVarFileName, |
| 90 | } |
| 91 | |
| 92 | resp, err := wshclient.GetVarCommand(RpcClient, commandData, &wshrpc.RpcOpts{Timeout: 2000}) |
| 93 | if err != nil { |
| 94 | return fmt.Errorf("getting variable: %w", err) |
| 95 | } |
| 96 | |
| 97 | if !resp.Exists { |
| 98 | WshExitCode = 1 |
| 99 | return nil |
| 100 | } |
| 101 | |
| 102 | WriteStdout("%s", resp.Val) |
| 103 | if shouldPrintNewline() { |
| 104 | WriteStdout("\n") |
| 105 | } |
| 106 | |
| 107 | return nil |
| 108 | } |
| 109 | |
| 110 | func getAllVariables(zoneId string) error { |
| 111 | commandData := wshrpc.CommandVarData{ |
nothing calls this directly
no test coverage detected