@@ -27,6 +27,7 @@ import (
27
27
"time"
28
28
29
29
"github.com/cloudfoundry-community/vaultkv"
30
+ "github.com/jhunt/go-ansi"
30
31
fmt "github.com/jhunt/go-ansi"
31
32
"github.com/jhunt/go-cli"
32
33
env "github.com/jhunt/go-envirotron"
@@ -259,9 +260,8 @@ type Options struct {
259
260
DataOnly bool `cli:"--data-only"`
260
261
} `cli:"curl"`
261
262
262
- UUID struct {
263
- UUID string
264
- } `cli:"uuid"`
263
+ UUID struct {} `cli:"uuid"`
264
+ Option struct {} `cli:"option"`
265
265
266
266
X509 struct {
267
267
Validate struct {
@@ -2882,6 +2882,82 @@ The following options are recognized:
2882
2882
return nil
2883
2883
})
2884
2884
2885
+ r .Dispatch ("option" , & Help {
2886
+ Summary : "View or edit global safe CLI options" ,
2887
+ Usage : "safe option [optionname=value]" ,
2888
+ Type : AdministrativeCommand ,
2889
+ Description : `
2890
+ Currently available options are:
2891
+
2892
+ @G{manage_vault_token} If set to true, then when logging in or switching targets,
2893
+ the '.vault-token' file in your $HOME directory that the Vault CLI uses will be
2894
+ updated.
2895
+ ` ,
2896
+ }, func (command string , args ... string ) error {
2897
+ cfg := rc .Apply (opt .UseTarget )
2898
+
2899
+ optLookup := []struct {
2900
+ opt string
2901
+ val * bool
2902
+ }{
2903
+ {"manage_vault_token" , & cfg .Options .ManageVaultToken },
2904
+ }
2905
+
2906
+ if len (args ) == 0 {
2907
+ table := table {}
2908
+ for _ , entry := range optLookup {
2909
+ value := "@R{false}"
2910
+ if * entry .val {
2911
+ value = "@G{true}"
2912
+ }
2913
+ table .addRow (entry .opt , ansi .Sprintf (value ))
2914
+ }
2915
+
2916
+ table .print ()
2917
+ return nil
2918
+ }
2919
+
2920
+ for _ , arg := range args {
2921
+ argSplit := strings .Split (arg , "=" )
2922
+ if len (argSplit ) != 2 {
2923
+ return fmt .Errorf ("Option arg syntax: option=value" )
2924
+ }
2925
+
2926
+ parseTrueFalse := func (s string ) (bool , error ) {
2927
+ switch s {
2928
+ case "true" , "on" , "yes" :
2929
+ return true , nil
2930
+ case "false" , "off" , "no" :
2931
+ return false , nil
2932
+ }
2933
+
2934
+ return false , fmt .Errorf ("value must be one of true|on|yes|false|off|no" )
2935
+ }
2936
+
2937
+ optionKey := strings .ReplaceAll (argSplit [0 ], "-" , "_" )
2938
+ optionVal , err := parseTrueFalse (argSplit [1 ])
2939
+ if err != nil {
2940
+ return err
2941
+ }
2942
+
2943
+ found := false
2944
+ for _ , opt := range optLookup {
2945
+ if opt .opt == optionKey {
2946
+ found = true
2947
+ * opt .val = optionVal
2948
+ ansi .Printf ("updated @G{%s}\n " , opt .opt )
2949
+ break
2950
+ }
2951
+ }
2952
+
2953
+ if ! found {
2954
+ return fmt .Errorf ("unknown option: %s" , argSplit [0 ])
2955
+ }
2956
+ }
2957
+
2958
+ return cfg .Write ()
2959
+ })
2960
+
2885
2961
r .Dispatch ("ssh" , & Help {
2886
2962
Summary : "Generate one or more new SSH RSA keypair(s)" ,
2887
2963
Usage : "safe ssh [NBITS] PATH [PATH ...]" ,
0 commit comments