2626using GitHub . Services . WebApi ;
2727using System . CommandLine . Builder ;
2828using System . CommandLine . Binding ;
29+ using System . CommandLine . Parsing ;
2930using System . Security . Cryptography ;
3031using System . Security . Cryptography . X509Certificates ;
3132using GitHub . Runner . Common ;
@@ -169,6 +170,7 @@ private class Parameters {
169170 public string [ ] LocalRepositories { get ; set ; }
170171 public bool Trace { get ; set ; }
171172 public bool Json { get ; set ; }
173+ public bool ListOptions { get ; set ; }
172174 public Parameters ShallowCopy ( )
173175 {
174176 return ( Parameters ) this . MemberwiseClone ( ) ;
@@ -1006,7 +1008,7 @@ static int Main(string[] args)
10061008 var verboseOpt = new Option < bool > (
10071009 new [ ] { "-v" , "--verbose" } ,
10081010 "Print more details like server / runner logs to stdout" ) ;
1009- var parallelOpt = new Option < int ? > (
1011+ var parallelOpt = new Option < int > (
10101012 "--parallel" ,
10111013 description : "Run n parallel runners" ) ;
10121014 var noCopyGitDirOpt = new Option < bool > (
@@ -1080,6 +1082,9 @@ static int Main(string[] args)
10801082 var localrepositoriesOpt = new Option < string [ ] > (
10811083 "--local-repository" ,
10821084 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" ) ;
10831088 var rootCommand = new RootCommand
10841089 {
10851090 workflowOption ,
@@ -1139,6 +1144,7 @@ static int Main(string[] args)
11391144 shaOpt ,
11401145 refOpt ,
11411146 localrepositoriesOpt ,
1147+ listOptionsOpt ,
11421148 } ;
11431149
11441150 rootCommand . Description = "Run your workflows locally." ;
@@ -1178,6 +1184,15 @@ static int Main(string[] args)
11781184 // Note that the parameters of the handler method are matched according to the names of the options
11791185 Func < Parameters , Task < int > > handler = async ( parameters ) =>
11801186 {
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+
11811196 var expandAzurePipeline = string . Equals ( parameters . Event , "azexpand" , StringComparison . OrdinalIgnoreCase ) ;
11821197 if ( parameters . Parallel == null && ! parameters . StartServer && ! parameters . List && ! expandAzurePipeline ) {
11831198 parameters . Parallel = 1 ;
@@ -2538,6 +2553,7 @@ await Task.WhenAny(Task.Run(() => {
25382553 parameters . Interactive = bindingContext . ParseResult . GetValueForOption ( interactiveOpt ) ;
25392554 parameters . Trace = bindingContext . ParseResult . GetValueForOption ( traceOpt ) ;
25402555 parameters . Json = bindingContext . ParseResult . GetValueForOption ( jsonOpt ) ;
2556+ parameters . ListOptions = bindingContext . ParseResult . GetValueForOption ( listOptionsOpt ) ;
25412557 parameters . Quiet = bindingContext . ParseResult . GetValueForOption ( quietOpt ) ;
25422558 parameters . Privileged = bindingContext . ParseResult . GetValueForOption ( privilegedOpt ) ;
25432559 parameters . Userns = bindingContext . ParseResult . GetValueForOption ( usernsOpt ) ;
@@ -2546,7 +2562,7 @@ await Task.WhenAny(Task.Run(() => {
25462562 parameters . KeepContainer = bindingContext . ParseResult . GetValueForOption ( keepContainerOpt ) ;
25472563 parameters . Directory = bindingContext . ParseResult . GetValueForOption ( DirectoryOpt ) ;
25482564 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 ;
25502566 parameters . NoCopyGitDir = bindingContext . ParseResult . GetValueForOption ( noCopyGitDirOpt ) ;
25512567 parameters . KeepRunnerDirectory = bindingContext . ParseResult . GetValueForOption ( keepRunnerDirectoryOpt ) ;
25522568 parameters . RunnerDirectory = bindingContext . ParseResult . GetValueForOption ( runnerDirectoryOpt ) ;
0 commit comments