@@ -4,13 +4,13 @@ namespace EssentialCSharp.ListingManager;
44
55public sealed class Program
66{
7- private static Task < int > Main ( string [ ] args )
7+ private static async Task < int > Main ( string [ ] args )
88 {
9- CommandLineConfiguration configuration = GetConfiguration ( ) ;
10- return configuration . InvokeAsync ( args ) ;
9+ RootCommand rootCommand = GetRootCommand ( ) ;
10+ return await rootCommand . Parse ( args ) . InvokeAsync ( ) ;
1111 }
1212
13- public static CommandLineConfiguration GetConfiguration ( )
13+ public static RootCommand GetRootCommand ( )
1414 {
1515 // Use the ExistingOnly method to only parse the arguments that are defined in the configuration
1616
@@ -47,24 +47,22 @@ public static CommandLineConfiguration GetConfiguration()
4747 Description = "All listings are in a single directory and not separated into chapter and chapter test directories." ,
4848 } ;
4949
50- Command listingUpdating = new ( "update" , "Updates namespaces and filenames for all listings and accompanying tests within a chapter" )
51- {
52- directoryInArgument ,
53- verboseOption ,
54- previewOption ,
55- byFolderOption ,
56- singleDirOption ,
57- allChaptersOption
58- } ;
50+ Command listingUpdating = new ( "update" , "Updates namespaces and filenames for all listings and accompanying tests within a chapter" ) ;
51+ listingUpdating . Arguments . Add ( directoryInArgument ) ;
52+ listingUpdating . Options . Add ( verboseOption ) ;
53+ listingUpdating . Options . Add ( previewOption ) ;
54+ listingUpdating . Options . Add ( byFolderOption ) ;
55+ listingUpdating . Options . Add ( singleDirOption ) ;
56+ listingUpdating . Options . Add ( allChaptersOption ) ;
5957
6058 listingUpdating . SetAction ( ( ParseResult parseResult ) =>
6159 {
62- DirectoryInfo directoryIn = parseResult . CommandResult . GetValue ( directoryInArgument ) ! ;
63- bool verbose = parseResult . CommandResult . GetValue ( verboseOption ) ;
64- bool preview = parseResult . CommandResult . GetValue ( previewOption ) ;
65- bool byFolder = parseResult . CommandResult . GetValue ( byFolderOption ) ;
66- bool singleDir = parseResult . CommandResult . GetValue ( singleDirOption ) ;
67- bool allChapters = parseResult . CommandResult . GetValue ( allChaptersOption ) ;
60+ DirectoryInfo directoryIn = parseResult . GetValue ( directoryInArgument ) ! ;
61+ bool verbose = parseResult . GetValue ( verboseOption ) ;
62+ bool preview = parseResult . GetValue ( previewOption ) ;
63+ bool byFolder = parseResult . GetValue ( byFolderOption ) ;
64+ bool singleDir = parseResult . GetValue ( singleDirOption ) ;
65+ bool allChapters = parseResult . GetValue ( allChaptersOption ) ;
6866
6967 Console . WriteLine ( $ "Updating listings within: { directoryIn } ") ;
7068 ListingManager listingManager = new ( directoryIn ) ;
@@ -80,14 +78,12 @@ public static CommandLineConfiguration GetConfiguration()
8078
8179 Command scan = new ( "scan" , "Scans for various things" ) ;
8280
83- Command listings = new ( "listings" , "Scans for mismatched listings" )
84- {
85- directoryInArgument
86- } ;
81+ Command listings = new ( "listings" , "Scans for mismatched listings" ) ;
82+ listings . Arguments . Add ( directoryInArgument ) ;
8783
8884 listings . SetAction ( ( ParseResult parseResult ) =>
8985 {
90- DirectoryInfo directoryIn = parseResult . CommandResult . GetValue ( directoryInArgument ) ! ;
86+ DirectoryInfo directoryIn = parseResult . GetValue ( directoryInArgument ) ! ;
9187 var extraListings = ListingManager . GetAllExtraListings ( directoryIn . FullName ) . OrderBy ( x => x ) ;
9288
9389 Console . WriteLine ( "---Extra Listings---" ) ;
@@ -96,20 +92,19 @@ public static CommandLineConfiguration GetConfiguration()
9692 Console . WriteLine ( extraListing ) ;
9793 }
9894 } ) ;
95+
9996 scan . Subcommands . Add ( listings ) ;
10097
101- Command tests = new ( "tests" , "Scans for mismatched tests" )
102- {
103- directoryInArgument ,
104- allChaptersOption ,
105- singleDirOption
106- } ;
98+ Command tests = new ( "tests" , "Scans for mismatched tests" ) ;
99+ tests . Arguments . Add ( directoryInArgument ) ;
100+ tests . Options . Add ( allChaptersOption ) ;
101+ tests . Options . Add ( singleDirOption ) ;
107102
108103 tests . SetAction ( ( ParseResult parseResult ) =>
109104 {
110- DirectoryInfo directoryIn = parseResult . CommandResult . GetValue ( directoryInArgument ) ! ;
111- bool allChapters = parseResult . CommandResult . GetValue ( allChaptersOption ) ;
112- bool singleDir = parseResult . CommandResult . GetValue ( singleDirOption ) ;
105+ DirectoryInfo directoryIn = parseResult . GetValue ( directoryInArgument ) ! ;
106+ bool allChapters = parseResult . GetValue ( allChaptersOption ) ;
107+ bool singleDir = parseResult . GetValue ( singleDirOption ) ;
113108
114109 Console . WriteLine ( "---Missing Tests---" ) ;
115110 if ( allChapters )
@@ -124,12 +119,10 @@ public static CommandLineConfiguration GetConfiguration()
124119
125120 scan . Subcommands . Add ( tests ) ;
126121
127- RootCommand rootCommand = new ( "The EssentialCSharp.ListingManager helps to organize and manage the EssentialCSharp source code" )
128- {
129- listingUpdating ,
130- scan
131- } ;
122+ RootCommand rootCommand = new ( "The EssentialCSharp.ListingManager helps to organize and manage the EssentialCSharp source code" ) ;
123+ rootCommand . Subcommands . Add ( listingUpdating ) ;
124+ rootCommand . Subcommands . Add ( scan ) ;
132125
133- return new CommandLineConfiguration ( rootCommand ) ;
126+ return rootCommand ;
134127 }
135- }
128+ }
0 commit comments