From a427010099c0b7a108f05daaafaeeebafa253220 Mon Sep 17 00:00:00 2001 From: Username404-59 Date: Fri, 26 Feb 2021 20:28:53 +0100 Subject: [PATCH] Complete scripts/fish-completion.fish, improve scripts/ybcon.sh and add a --version argument. --- CMakeLists.txt | 1 + scripts/bash-completion.sh | 2 +- scripts/fish-completion.fish | 8 ++++- scripts/ybcon.sh | 57 ++++++++++++++++++++++-------------- src/main.cpp | 5 ++++ 5 files changed, 49 insertions(+), 24 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c153b5..031d929 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,7 @@ set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${CMAKE_PROJECT_VERSION}-${TI include_directories(${CMAKE_CURRENT_LIST_DIR}) add_executable(ybcon src/main.cpp resources/Yerbacon.rc src/parser/MainParse.cpp src/transpiler/MainTranspile.cpp src/etc/filefuncs.cpp src/etc/lexer.cpp src/headers/lex.hpp) +target_compile_definitions(ybcon PRIVATE YBCON_VERSION="${PROJECT_VERSION}") # lpkg = linux package, wpkg = windows package if (UNIX AND NOT MINGW) diff --git a/scripts/bash-completion.sh b/scripts/bash-completion.sh index 26c793d..f934a71 100644 --- a/scripts/bash-completion.sh +++ b/scripts/bash-completion.sh @@ -5,7 +5,7 @@ _ybconAutoComplete() { COMPREPLY=() current="${COMP_WORDS[COMP_CWORD]}" previous="${COMP_WORDS[COMP_CWORD-1]}" - options='-h -p --help --printresult' + options='-h -p --help --version --printresult' if [[ "${current}" == -* ]]; then COMPREPLY=("$(compgen -W "$options" -- "$current")") return 0 diff --git a/scripts/fish-completion.fish b/scripts/fish-completion.fish index 7bb5a63..3c187e6 100644 --- a/scripts/fish-completion.fish +++ b/scripts/fish-completion.fish @@ -1 +1,7 @@ -set -l commands --help -p --printresult \ No newline at end of file +set -l commands --help -p --printresult + +complete -c ybcon -f +complete -c ybcon -s h -l help -d "Print the help screen" +complete -c ybcon -l version -d "Print the version" +complete -c ybcon -s p -l printresult -d "Enable printing the transpilation result to stdout" +complete -c ybcon -a "(__fish_complete_suffix .ybcon)" \ No newline at end of file diff --git a/scripts/ybcon.sh b/scripts/ybcon.sh index 808fc56..cec5382 100755 --- a/scripts/ybcon.sh +++ b/scripts/ybcon.sh @@ -8,13 +8,18 @@ EXENAME=ybcon defaultBinLocation=/opt/bin/ybcon usage() { - echo "$EXENAME [-h|--help] [-p|--printresult] file" - echo " -h or --help What you're seeing right now" - echo " -p or --printresult Prints the transpilation result to stdout" + if [ "$1" = false ]; then echo "Invalid arguments, usage:"; fi + echo "$EXENAME [--version] [-h|--help] [-p|--printresult] file" + if [ "$1" = true ]; then + echo " --version Print the version" + echo " -h or --help What you're seeing right now" + echo " -p or --printresult Enable printing the transpilation result to stdout" + fi } args=""; run=false; +skipArgsIteration=false; newArgs() { if [ "$args" = "" ]; then @@ -25,26 +30,34 @@ newArgs() { } if [ "$#" != 0 ]; then - for it in "$@" - do - case "$it" in - -h | --help ) - echo "Usage:" - usage - exit 0 ;; - -p | --printresult ) - newArgs "$it" - shift ;; - *.ybcon ) - newArgs "$it" - run=true - break ;; - * ) - usage ;; - esac - done + if [ "$#" = 1 ]; then + if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then + usage true + exit 0; + elif [ "$1" = "--version" ]; then + run=true + args="$1" + skipArgsIteration=false; + fi + fi + if [ $skipArgsIteration = true ]; then + for it in "$@" + do + case "$it" in + -p | --printresult ) + newArgs "$it" + shift ;; + *.ybcon ) + newArgs "$it" + run=true + break ;; + * ) + usage false ;; + esac + done + fi else - usage + usage false fi runIt() { eval "$1" " $args"; } diff --git a/src/main.cpp b/src/main.cpp index aca619e..f0316a7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,6 +2,10 @@ #include using namespace std; +#ifndef YBCON_VERSION +#define YBCON_VERSION "UNKNOWN" +#endif + extern string getFileContent(const string& file); extern void setOutputFileContent(const string& language, const string& file, const string& content); extern string parseString(unique_ptr toParse); @@ -9,6 +13,7 @@ extern string parseString(unique_ptr toParse); extern string transpile(string toTranspile, string language); int main(int argc, char* argv[]) { + if ((argc == 2) && (((string) argv[1]) == "--version")) { cout << YBCON_VERSION << endl; exit(0); } string fileName = (argv[argc - 1] != nullptr) ? argv[argc - 1] : "none" ; if (fileName != "none" and fileName.ends_with(".ybcon")) {