@@ -8,6 +8,7 @@ public class HashProgram
88 public const ConsoleColor ErrorColor = ConsoleColor . DarkRed ;
99 public const ConsoleColor SuccessColor = ConsoleColor . Green ;
1010
11+ [ STAThread ]
1112 static void Main ( string [ ] args )
1213 {
1314 string ? pathEnv = Environment . GetEnvironmentVariable ( "Path" , EnvironmentVariableTarget . Machine ) ;
@@ -32,7 +33,7 @@ static void Start(string[] args)
3233 {
3334 if ( args . Length == 0 )
3435 {
35- WriteColored ( "Use " , FlagColor , "--help" , " or " , FlagColor , "-h" , " flags, to see usage list \n " ) ;
36+ HelpHandler ( ) ;
3637 return ;
3738 }
3839 if ( args [ 0 ] == "--test" || args [ 0 ] == "-t" )
@@ -42,16 +43,18 @@ static void Start(string[] args)
4243 }
4344 if ( args [ 0 ] == "--help" || args [ 0 ] == "-h" )
4445 {
45- WriteColored ( "Usage: hash-cli [ hash-algorithm ] [ raw-data ]\n " +
46- " " , FlagColor , "--file" , " [ file_path ]\n " +
47- " " , FlagColor , "--checksum" , " [ hash-algorithm ] [ file-path ] [ file-hash-sum-path ]\n " +
48- " " , FlagColor , "--checksum" , " [ hash-algorithm ] [ file-path ] " , FlagColor , "--hash" , " [ hash-sum ]\n " ) ;
46+ HelpHandler ( ) ;
4947 return ;
5048 }
5149
5250 if ( args [ 0 ] == "--checksum" || args [ 0 ] == "-cs" )
5351 {
5452 string algorithmString = args [ 1 ] ;
53+ if ( algorithmString == "-h" || algorithmString == "--help" )
54+ {
55+ HelpHandler ( "checksum" ) ;
56+ return ;
57+ }
5558 Algorithm algorithm = Algorithm . Sha1 ;
5659 string path = args [ 2 ] ;
5760 string hashPath = args [ 3 ] ;
@@ -240,4 +243,19 @@ public static void ErrorHandler(Exception e)
240243 {
241244 WriteColored ( "\n Missing argument: use " , FlagColor , "--help" , " or " , FlagColor , "-h" , " flags, to see usage list\n " , ErrorColor , "Error: " , e . Message ) ;
242245 }
246+
247+ public static void HelpHandler ( string command = "" )
248+ {
249+ if ( command == "checksum" )
250+ {
251+ WriteColored ( "\n Usage: hash-cli [ hash-algorithm ] [ file-path ] [ file-hash-sum-path ]\n \n " , FlagColor , "or" , "\n \n hash-cli [ hash-algorithm ] [ file-path ]" , FlagColor , " --hash" , " [ hash-sum ]\n \n Example: hash-cli crc32 ./example.md" , FlagColor , " --hash" , " 2a0d96ed" ) ;
252+ }
253+ else
254+ {
255+ WriteColored ( "\n Usage: hash-cli [ hash-algorithm ] [ raw-data ]\n " +
256+ " " , FlagColor , "--file" , " [ file_path ]\n " +
257+ " " , FlagColor , "--checksum" , " [ hash-algorithm ] [ file-path ] [ file-hash-sum-path ]\n " +
258+ " " , FlagColor , "--checksum" , " [ hash-algorithm ] [ file-path ] " , FlagColor , "--hash" , " [ hash-sum ]\n " ) ;
259+ }
260+ }
243261}
0 commit comments