#define BOB_IMPLEMENTATION
#include "bob.hpp"
#include <cstdlib>
#include <unistd.h>
using namespace std;
int main(int argc, char* argv[]) {
GO_REBUILD_YOURSELF(argc, argv);
Cli cli(
"Bob CLI Example", argc, argv);
cli.
add_flag(
"verbose",
'v', CliFlagType::Bool,
"Enable verbose output");
cout << "Hello, my name is Bob!" << endl;
return EXIT_FAILURE;
});
cout << "This is the FIRST subcommand!!" << endl;
return EXIT_SUCCESS;
});
cout << "This is the SECOND subcommand!!" << endl;
return EXIT_SUCCESS;
});
cout << "Path: ";
for (
const auto &part : cmd.
path) {
cout << part << " ";
}
cout << endl;
return EXIT_SUCCESS;
});
cout << "Arguments:" << endl;
for (
int i = 0; i < cmd.
args.size(); ++i) {
cout <<
" argv[" << i <<
"]: " << cmd.
args[i] << endl;
}
return EXIT_SUCCESS;
});
cli.
add_command(
"flags",
"Prints prints its flag arguments and their values", [](
CliCommand &cmd) ->
int {
for (
const auto &flag : cmd.
flags) {
cout << " Argument: " << (flag.long_name.empty() ? "<empty>" : flag.long_name)
<< " (short: " << (flag.short_name ? string({flag.short_name}) : "<empty>") << ")"
<< ", Type: " << (flag.type == CliFlagType::Bool ? "Flag" : "Option")
<< ", Value: " << (flag.value.empty() ? "<none>" : flag.value)
<< ", Set: " << (flag.set ? "true" : "false") << endl;
}
return EXIT_SUCCESS;
})
.add_flag("an-argument", 'a', CliFlagType::Value, "An argument with a value")
.
add_flag(
"flag",
'f', CliFlagType::Bool,
"A simple flag argument")
.
add_flag(
"better-v",
'v', CliFlagType::Bool,
"A better -v flag than the global one");
return cli.serve();
}
Represents a CLI command.
Definition bob.hpp:579
CliCommand & add_command(CliCommand command)
vector< string > args
Arguments that are not flags.
Definition bob.hpp:584
vector< string > path
Path to the command, e.g. {"./bob", "test", "run"}.
Definition bob.hpp:582
CliCommand & add_flag(const CliFlag &arg)
Adds a flag argument to this command.
void handle_help()
Prints the help message if the --help flag is set.
vector< CliFlag > flags
The flags provided to this command.
Definition bob.hpp:593
A command line interface (CLI) that can be used to run commands and subcommands.
Definition bob.hpp:654
Contains the functionality of the Bob build system.
Definition bob.hpp:47