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:
593
593
A private option will not accept environment variables or command line flags,
594
594
and it will not appear in the help documentation.
595
595
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
+
596
619
# ### Shared Options
597
620
598
621
Options 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:
813
813
{
814
814
"rewrite" ,
815
815
`
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
+ `
816
843
tasks:
817
844
mytask:
818
845
options:
819
846
foo:
820
847
type: bool
821
848
rewrite: newvalue
822
- run: echo ${foo}
849
+ bar:
850
+ default:
851
+ when:
852
+ equal: {foo: newvalue}
853
+ value: barvalue
854
+ run: echo ${bar}
823
855
` ,
824
856
[]string {},
825
857
map [string ]string {
@@ -828,8 +860,38 @@ tasks:
828
860
"mytask" ,
829
861
marshal.Slice [* Run ]{{
830
862
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" ,
833
895
}},
834
896
}},
835
897
},
@@ -1113,29 +1175,6 @@ tasks:
1113
1175
type: string
1114
1176
rewrite: newvalue
1115
1177
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}
1139
1178
` ,
1140
1179
flags : map [string ]string {
1141
1180
"foo" : "true" ,
You can’t perform that action at this time.
0 commit comments