File tree Expand file tree Collapse file tree 2 files changed +88
-26
lines changed
Expand file tree Collapse file tree 2 files changed +88
-26
lines changed Original file line number Diff line number Diff line change @@ -593,6 +593,29 @@ options:
593593A private option will not accept environment variables or command line flags,
594594and it will not appear in the help documentation.
595595
596+ # ### Option Rewrite
597+
598+ Boolean values are convenient as CLI inputs, but the interpolated output of
599+ ` true` or `false` is often not. Use the `rewrite` clause to change the
600+ interpolation behavior from `true`/`false` to a conditional specified string :
601+
602+ ` ` ` yaml
603+ tasks:
604+ greet:
605+ options:
606+ verbose:
607+ type: boolean
608+ rewrite: --level=verbose
609+ run: mycli greet ${verbose}
610+ ` ` `
611+
612+ The above will interpolate to eitehr `mycli greet` or `mycli greet --level=verbose`
613+ depending on whether the `--verbose` flag is passed.
614+
615+ Note that once a boolean option has been rewritten, the output is no longer
616+ `true`/`false`, which means `when : verbose` in the above example would never
617+ evaluate to true.
618+
596619# ### Shared Options
597620
598621Options may also be defined at the root of the config file to be shared between
Original file line number Diff line number Diff line change @@ -813,13 +813,45 @@ tasks:
813813 {
814814 "rewrite" ,
815815 `
816+ tasks:
817+ mytask:
818+ options:
819+ foo:
820+ type: bool
821+ rewrite: foovalue
822+ bar:
823+ type: bool
824+ rewrite: barvalue
825+ run: echo ${foo} ${bar}
826+ ` ,
827+ []string {},
828+ map [string ]string {
829+ "foo" : "true" ,
830+ },
831+ "mytask" ,
832+ marshal.Slice [* Run ]{{
833+ Command : marshal.Slice [* Command ]{{
834+ Exec : "echo foovalue" ,
835+ Print : "echo foovalue" ,
836+ }},
837+ }},
838+ },
839+
840+ {
841+ "chained rewrite" ,
842+ `
816843tasks:
817844 mytask:
818845 options:
819846 foo:
820847 type: bool
821848 rewrite: newvalue
822- run: echo ${foo}
849+ bar:
850+ default:
851+ when:
852+ equal: {foo: newvalue}
853+ value: barvalue
854+ run: echo ${bar}
823855` ,
824856 []string {},
825857 map [string ]string {
@@ -828,8 +860,38 @@ tasks:
828860 "mytask" ,
829861 marshal.Slice [* Run ]{{
830862 Command : marshal.Slice [* Command ]{{
831- Exec : "echo newvalue" ,
832- Print : "echo newvalue" ,
863+ Exec : "echo barvalue" ,
864+ Print : "echo barvalue" ,
865+ }},
866+ }},
867+ },
868+
869+ // This isn't really desirable, but we might as well capture that the
870+ // behavior works the way it's expected to work.
871+ {
872+ "chained non-boolean rewrite" ,
873+ `
874+ tasks:
875+ mytask:
876+ options:
877+ foo:
878+ type: bool
879+ rewrite: newvalue
880+ bar:
881+ default:
882+ when: foo
883+ value: barvalue
884+ run: echo ${bar}
885+ ` ,
886+ []string {},
887+ map [string ]string {
888+ "foo" : "true" ,
889+ },
890+ "mytask" ,
891+ marshal.Slice [* Run ]{{
892+ Command : marshal.Slice [* Command ]{{
893+ Exec : "echo" ,
894+ Print : "echo" ,
833895 }},
834896 }},
835897 },
@@ -1113,29 +1175,6 @@ tasks:
11131175 type: string
11141176 rewrite: newvalue
11151177 run: echo ${bar}
1116- ` ,
1117- flags : map [string ]string {
1118- "foo" : "true" ,
1119- },
1120- taskName : "mytask" ,
1121- wantErr : "rewrite may only be performed on boolean values" ,
1122- },
1123-
1124- {
1125- name : "chained rewrite" ,
1126- input : `
1127- tasks:
1128- mytask:
1129- options:
1130- foo:
1131- type: bool
1132- rewrite: newvalue
1133- bar:
1134- default:
1135- when:
1136- equal: {foo: newvalue}
1137- rewrite: barvalue
1138- run: echo ${bar}
11391178` ,
11401179 flags : map [string ]string {
11411180 "foo" : "true" ,
You can’t perform that action at this time.
0 commit comments