26
26
using GitHub . Services . WebApi ;
27
27
using System . CommandLine . Builder ;
28
28
using System . CommandLine . Binding ;
29
+ using System . CommandLine . Parsing ;
29
30
using System . Security . Cryptography ;
30
31
using System . Security . Cryptography . X509Certificates ;
31
32
using GitHub . Runner . Common ;
@@ -169,6 +170,7 @@ private class Parameters {
169
170
public string [ ] LocalRepositories { get ; set ; }
170
171
public bool Trace { get ; set ; }
171
172
public bool Json { get ; set ; }
173
+ public bool ListOptions { get ; set ; }
172
174
public Parameters ShallowCopy ( )
173
175
{
174
176
return ( Parameters ) this . MemberwiseClone ( ) ;
@@ -1006,7 +1008,7 @@ static int Main(string[] args)
1006
1008
var verboseOpt = new Option < bool > (
1007
1009
new [ ] { "-v" , "--verbose" } ,
1008
1010
"Print more details like server / runner logs to stdout" ) ;
1009
- var parallelOpt = new Option < int ? > (
1011
+ var parallelOpt = new Option < int > (
1010
1012
"--parallel" ,
1011
1013
description : "Run n parallel runners" ) ;
1012
1014
var noCopyGitDirOpt = new Option < bool > (
@@ -1080,6 +1082,9 @@ static int Main(string[] args)
1080
1082
var localrepositoriesOpt = new Option < string [ ] > (
1081
1083
"--local-repository" ,
1082
1084
description : "Redirect dependent repositories to the local filesystem. E.g `--local-repository org/name@ref=/path/to/repository`" ) ;
1085
+ var listOptionsOpt = new Option < bool > (
1086
+ "--list-options" ,
1087
+ description : "Print a json structure of compatible options" ) ;
1083
1088
var rootCommand = new RootCommand
1084
1089
{
1085
1090
workflowOption ,
@@ -1139,6 +1144,7 @@ static int Main(string[] args)
1139
1144
shaOpt ,
1140
1145
refOpt ,
1141
1146
localrepositoriesOpt ,
1147
+ listOptionsOpt ,
1142
1148
} ;
1143
1149
1144
1150
rootCommand . Description = "Run your workflows locally." ;
@@ -1178,6 +1184,15 @@ static int Main(string[] args)
1178
1184
// Note that the parameters of the handler method are matched according to the names of the options
1179
1185
Func < Parameters , Task < int > > handler = async ( parameters ) =>
1180
1186
{
1187
+ if ( parameters . ListOptions ) {
1188
+ var options = new JArray ( ) ;
1189
+ foreach ( var opt in rootCommand . Options ) {
1190
+ options . Add ( JObject . FromObject ( new { name = opt . Name , aliases = opt . Aliases , required = opt . IsRequired , @default = ( opt as IValueDescriptor ) . HasDefaultValue ? ( opt as IValueDescriptor ) . GetDefaultValue ( ) : null , description = opt . Description , @type = TypeHelper . GetTypeName ( opt . ValueType ) , minValues = opt . Arity . MinimumNumberOfValues , maxValues = opt . Arity . MaximumNumberOfValues } ) ) ;
1191
+ }
1192
+ Console . WriteLine ( options ) ;
1193
+ return 0 ;
1194
+ }
1195
+
1181
1196
var expandAzurePipeline = string . Equals ( parameters . Event , "azexpand" , StringComparison . OrdinalIgnoreCase ) ;
1182
1197
if ( parameters . Parallel == null && ! parameters . StartServer && ! parameters . List && ! expandAzurePipeline ) {
1183
1198
parameters . Parallel = 1 ;
@@ -2538,6 +2553,7 @@ await Task.WhenAny(Task.Run(() => {
2538
2553
parameters . Interactive = bindingContext . ParseResult . GetValueForOption ( interactiveOpt ) ;
2539
2554
parameters . Trace = bindingContext . ParseResult . GetValueForOption ( traceOpt ) ;
2540
2555
parameters . Json = bindingContext . ParseResult . GetValueForOption ( jsonOpt ) ;
2556
+ parameters . ListOptions = bindingContext . ParseResult . GetValueForOption ( listOptionsOpt ) ;
2541
2557
parameters . Quiet = bindingContext . ParseResult . GetValueForOption ( quietOpt ) ;
2542
2558
parameters . Privileged = bindingContext . ParseResult . GetValueForOption ( privilegedOpt ) ;
2543
2559
parameters . Userns = bindingContext . ParseResult . GetValueForOption ( usernsOpt ) ;
@@ -2546,7 +2562,7 @@ await Task.WhenAny(Task.Run(() => {
2546
2562
parameters . KeepContainer = bindingContext . ParseResult . GetValueForOption ( keepContainerOpt ) ;
2547
2563
parameters . Directory = bindingContext . ParseResult . GetValueForOption ( DirectoryOpt ) ;
2548
2564
parameters . Verbose = bindingContext . ParseResult . GetValueForOption ( verboseOpt ) ;
2549
- parameters . Parallel = bindingContext . ParseResult . GetValueForOption ( parallelOpt ) ;
2565
+ parameters . Parallel = bindingContext . ParseResult . HasOption ( parallelOpt ) ? bindingContext . ParseResult . GetValueForOption < int > ( parallelOpt ) : null ;
2550
2566
parameters . NoCopyGitDir = bindingContext . ParseResult . GetValueForOption ( noCopyGitDirOpt ) ;
2551
2567
parameters . KeepRunnerDirectory = bindingContext . ParseResult . GetValueForOption ( keepRunnerDirectoryOpt ) ;
2552
2568
parameters . RunnerDirectory = bindingContext . ParseResult . GetValueForOption ( runnerDirectoryOpt ) ;
0 commit comments