Here’s the translation of the Go code to Ada, with explanations in Markdown format suitable for Hugo:
Our program demonstrates the use of subcommands in Ada, similar to how tools like git have different subcommands (e.g., git pull, git push). We’ll use the GNAT.Command_Line package to parse command-line arguments and implement subcommands.
This Ada program implements subcommands similar to the original example. Here’s how it works:
We use the GNAT.Command_Line package to parse command-line arguments.
We define two procedures, Handle_Foo and Handle_Bar, to handle the “foo” and “bar” subcommands respectively.
In the main procedure, we check if a subcommand is provided and call the appropriate handler.
Each handler uses Getopt to parse its specific flags and then prints the results.
To compile and run the program:
Note that Ada’s command-line parsing is somewhat different from the Go example. We use short options (-e, -n, -l) instead of long options, and the syntax for specifying option values is slightly different.
If you try to use an undefined flag, Ada will raise an exception:
This example demonstrates how to implement subcommands and parse command-line arguments in Ada, providing similar functionality to the original Go program.