@@ -28,7 +28,10 @@ public static void Main(string[] args)
2828
2929    static async  Task  Run ( string [ ]  args ,  CancellationToken  ct ) 
3030    { 
31-         if  ( args . Length  ==  0 ) 
31+         string ?  action  =  args . Length  >  0  &&  ! args [ 0 ] . StartsWith ( '-' )  ?  args [ 0 ]  :  null ; 
32+         if  ( action  is  not null )  args  =  args [ 1 ..] ; 
33+ 
34+         if  ( action  is  null  &&  ( args . Contains ( "-h" )  ||  args . Contains ( "--help" )  ||  args . Length  ==  0 ) ) 
3235        { 
3336            Help . PrintHelp ( null ) ; 
3437            return ; 
@@ -42,16 +45,16 @@ static async Task Run(string[] args, CancellationToken ct)
4245            Actions . Install . PerformInstall ( ) ; 
4346        } 
4447
45-         switch  ( args [ 0 ] ) 
48+         switch  ( action ) 
4649        { 
4750            case  "update" : 
4851                if  ( args . ContainsAny ( "--help" ,  "-h" ) ) 
4952                { 
50-                     Help . PrintHelp ( args [ 0 ] ) ; 
53+                     Help . PrintHelp ( action ) ; 
5154                    break ; 
5255                } 
5356
54-                 if  ( args . Length  !=  1 ) 
57+                 if  ( args . Length  !=  0 ) 
5558                { 
5659                    throw  new  ApplicationArgumentsException ( $ "Wrong number of arguments passed") ; 
5760                } 
@@ -61,11 +64,11 @@ static async Task Run(string[] args, CancellationToken ct)
6164            case  "check" : 
6265                if  ( args . ContainsAny ( "--help" ,  "-h" ) ) 
6366                { 
64-                     Help . PrintHelp ( args [ 0 ] ) ; 
67+                     Help . PrintHelp ( action ) ; 
6568                    break ; 
6669                } 
6770
68-                 if  ( args . Length  !=  1 ) 
71+                 if  ( args . Length  !=  0 ) 
6972                { 
7073                    throw  new  ApplicationArgumentsException ( $ "Wrong number of arguments passed") ; 
7174                } 
@@ -75,39 +78,39 @@ static async Task Run(string[] args, CancellationToken ct)
7578            case  "add" : 
7679                if  ( args . ContainsAny ( "--help" ,  "-h" ) ) 
7780                { 
78-                     Help . PrintHelp ( args [ 0 ] ) ; 
81+                     Help . PrintHelp ( action ) ; 
7982                    break ; 
8083                } 
8184
82-                 if  ( args . Length  <  2 ) 
85+                 if  ( args . Length  <  1 ) 
8386                { 
8487                    throw  new  ApplicationArgumentsException ( $ "Wrong number of arguments passed") ; 
8588                } 
8689
87-                 await  Actions . Add . PerformAdd ( args [ 1 .. ] ,  ct ) ; 
90+                 await  Actions . Add . PerformAdd ( args ,  ct ) ; 
8891                break ; 
8992            case  "remove" : 
9093                if  ( args . ContainsAny ( "--help" ,  "-h" ) ) 
9194                { 
92-                     Help . PrintHelp ( args [ 0 ] ) ; 
95+                     Help . PrintHelp ( action ) ; 
9396                    break ; 
9497                } 
9598
96-                 if  ( args . Length  <  2 ) 
99+                 if  ( args . Length  <  1 ) 
97100                { 
98101                    throw  new  ApplicationArgumentsException ( $ "Wrong number of arguments passed") ; 
99102                } 
100103
101-                 await  Actions . Remove . PerformRemove ( args [ 1 .. ] ,  ct ) ; 
104+                 await  Actions . Remove . PerformRemove ( args ,  ct ) ; 
102105                break ; 
103106            case  "list" : 
104107                if  ( args . ContainsAny ( "--help" ,  "-h" ) ) 
105108                { 
106-                     Help . PrintHelp ( args [ 0 ] ) ; 
109+                     Help . PrintHelp ( action ) ; 
107110                    break ; 
108111                } 
109112
110-                 if  ( args . Length  !=  1 ) 
113+                 if  ( args . Length  !=  0 ) 
111114                { 
112115                    throw  new  ApplicationArgumentsException ( $ "Wrong number of arguments passed") ; 
113116                } 
@@ -117,25 +120,19 @@ static async Task Run(string[] args, CancellationToken ct)
117120            case  "change" : 
118121                if  ( args . ContainsAny ( "--help" ,  "-h" ) ) 
119122                { 
120-                     Help . PrintHelp ( args [ 0 ] ) ; 
123+                     Help . PrintHelp ( action ) ; 
121124                    break ; 
122125                } 
123126
124-                 if  ( args . Length  !=  2 ) 
127+                 if  ( args . Length  !=  1 ) 
125128                { 
126129                    throw  new  ApplicationArgumentsException ( $ "Wrong number of arguments passed") ; 
127130                } 
128131
129-                 await  Actions . Change . PerformChange ( args [ 1 ] ,  ct ) ; 
132+                 await  Actions . Change . PerformChange ( args [ 0 ] ,  ct ) ; 
130133                break ; 
131134            default : 
132-                 if  ( args . ContainsAny ( "--help" ,  "-h" ) ) 
133-                 { 
134-                     Help . PrintHelp ( null ) ; 
135-                     break ; 
136-                 } 
137- 
138-                 throw  new  ApplicationArgumentsException ( $ "Invalid action { args [ 0 ] } ") ; 
135+                 throw  new  ApplicationArgumentsException ( $ "Invalid action { action } ") ; 
139136        } 
140137    } 
141138} 
0 commit comments