INCLUDE_DIRECTORIES(${COMMON_FOLDER})
TARGET_LINK_LIBRARIES(${CLI_CODENAME} ${LIB_DEPS_LIBRARIES} ${PROJECT_NAME})
+CONFIGURE_FILE(support/vasum-cli-completion.sh.in
+ ${CMAKE_BINARY_DIR}/vasum-cli-completion.sh
+ @ONLY)
## Install #####################################################################
INSTALL(TARGETS ${CLI_CODENAME} DESTINATION bin)
+INSTALL(FILES ${CMAKE_BINARY_DIR}/vasum-cli-completion.sh
+ DESTINATION ${SYSCONF_INSTALL_DIR}/bash_completion.d)
{
out << mUsage << "\n\n"
<< "\tDescription\n"
- << "\t\t" << mUsageInfo << "\n\n"
- << "\tOptions\n";
- for (const auto& args : mArgsSpec) {
- out << "\t\t" << args.first << " -- " << args.second << "\n";
+ << "\t\t" << mUsageInfo << "\n";
+ if (!mArgsSpec.empty()) {
+ out << "\n\tOptions\n";
+ for (const auto& args : mArgsSpec) {
+ out << "\t\t" << args.first << " -- " << args.second << "\n";
+ }
}
out << "\n";
}
#include <stdexcept>
#include <string>
#include <iostream>
+#include <algorithm>
using namespace vasum::cli;
void printUsage(std::ostream& out, const std::string& name)
{
- out << "Usage: " << name << " [command [args]]\n\n"
+ out << "Usage: " << name << " [command [-h|args]]\n\n"
<< "command can be one of the following:\n";
for (const auto& command : commands) {
}
CommandLineInterface& command = commands[argv[1]];
+ auto it = std::find(argv, argv+argc, std::string("-h"));
+ if (it != argv + argc) {
+ command.printUsage(std::cout);
+ return EXIT_SUCCESS;
+ }
+
try {
command.execute(1, argc, argv);
} catch (const std::runtime_error& ex) {
--- /dev/null
+# Check for bash
+[ -z "$BASH_VERSION" ] && return
+
+__@PROJECT_NAME@_cli() {
+ local cur="${COMP_WORDS[COMP_CWORD]}"
+
+ COMPREPLY=()
+ if [ "$COMP_CWORD" == "1" ]; then
+ COMPREPLY=($(compgen -W "$(@CLI_CODENAME@ | grep -e '^\S' | tail -n +3 | cut -f1 -d' ')" -- $cur))
+ elif [ "$COMP_CWORD" == "2" ]; then
+ COMPREPLY=($(compgen -W "-h" -- $cur))
+ fi
+}
+
+complete -F __@PROJECT_NAME@_cli @CLI_CODENAME@
%defattr(644,root,root,755)
%attr(755,root,root) %{_bindir}/vasum-cli
+%package cli-completion
+Summary: Vasum Command Line Interface bash completion
+Group: Security/Other
+Requires: vasum-cli = %{version}-%{release}
+#Requires: bash-completion
+
+%description cli-completion
+Command Line Interface bash completion.
+
+%files cli-completion
+%attr(755,root,root) %{_sysconfdir}/bash_completion.d/vasum-cli-completion.sh
## Test Package ################################################################
%package tests