diff --git a/scripts/completions/bash-completion.sh b/scripts/completions/bash-completion.sh index fa1546e..7f69bb0 100644 --- a/scripts/completions/bash-completion.sh +++ b/scripts/completions/bash-completion.sh @@ -8,7 +8,7 @@ _ybconAutoComplete() { COMPREPLY=() current="${COMP_WORDS[COMP_CWORD]}" previous="${COMP_WORDS[COMP_CWORD-1]}" - options='-h -p -t --help --parallel --target= --newlines= --printresult --text --version --buildInfo' + options='-h -p -t -o --help --parallel --target= --newlines= --printresult --text --output --version --buildInfo' if [[ "${current}" == -* ]]; then YCompReply "$(compgen -W "$options" -- "$current")" return 0 diff --git a/scripts/completions/fish-completion.fish b/scripts/completions/fish-completion.fish index b88b157..88ee380 100644 --- a/scripts/completions/fish-completion.fish +++ b/scripts/completions/fish-completion.fish @@ -8,4 +8,5 @@ complete -c ybcon -l parallel -k -d "Transpile files in parallel mode" complete -c ybcon -l target -k -f -a 'lua js py' -d "Set the transpilation target" complete -c ybcon -l newlines -k -f -a 'on off' -d "Enable or disable new lines" complete -c ybcon -s p -l printresult -d "Enable printing the transpilation result to stdout" -complete -c ybcon -x -s t -l text -d "Transpile text provided after this argument (implies -p)" \ No newline at end of file +complete -c ybcon -x -s t -l text -d "Transpile text provided after this argument (implies -p)" +complete -c ybcon -x -s o -l output -a '(__fish_complete_directories)' -d 'Output the transpiled file(s) to the specified directory' \ No newline at end of file diff --git a/scripts/completions/zsh-completion.zsh b/scripts/completions/zsh-completion.zsh index 4d227d7..bd2cff0 100644 --- a/scripts/completions/zsh-completion.zsh +++ b/scripts/completions/zsh-completion.zsh @@ -10,6 +10,7 @@ _ybcon() { --newlines='[Enable or disable new lines]:state:(on off)' \ {-p,--printresult}'[Enable printing the transpilation result to stdout]' \ {-t,--text}'[Transpile text provided after this argument (implies -p)]' \ + {-o,--output}'[Output the transpiled file(s) to the specified directory]' \ "*:$completeyfile" return 0 } diff --git a/scripts/ybcon b/scripts/ybcon index 86a6ee8..f901c16 100755 --- a/scripts/ybcon +++ b/scripts/ybcon @@ -21,6 +21,7 @@ usage() { echo " --newlines=on/off Enable or disable new lines" echo " -p or --printresult Enable printing the transpilation result to stdout" echo " -t or --text Transpile text provided after this argument (implies -p)" + echo " -o or --output Output the transpiled file(s) to the specified directory" printf "\n" fi } diff --git a/src/main.cpp b/src/main.cpp index 11580e5..0e36ad5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,6 +19,7 @@ int main(int argc, char* argv[]) { using unit_result = pair>; using unit = future; map Units; + optional output_directory; #ifdef EMSCRIPTEN is_node = MAIN_THREAD_EM_ASM_INT({ return ENVIRONMENT_IS_NODE; }); #endif @@ -41,6 +42,10 @@ int main(int argc, char* argv[]) { } else goto invalid_argument; } else if (currentArgument == ArgumentShort("text")) printResult = text_provided = true; + else if (currentArgument == ArgumentShort("output")) + if ((not output_directory.has_value()) and Units.empty() and (i + 1) != argc) { + output_directory = argv[i + 1]; ++i; + } else goto invalid_argument; else if (text_provided || currentArgument.ends_with(".ybcon")) { #ifdef _OPENMP if (not parallel) omp_set_num_threads(1); @@ -71,13 +76,18 @@ int main(int argc, char* argv[]) { } #endif } - Units.insert_or_assign(currentArgument, async(not parallel ? launch::deferred : launch::async, [&, currentArgument, file_path]() { + Units.insert_or_assign(currentArgument, async(not parallel ? launch::deferred : launch::async, [&, currentArgument, file_path, index = Units.size() + 1]() { unit_result resultingPair; try { resultingPair.first = Target::forName(target, newLines)->transpileWithTree( parseString(text_provided ? currentArgument : getFileContent(file_path->string())) ); - if (not text_provided) outputFileContent(filesystem::path(file_path.value()).replace_extension(target).string(), resultingPair.first); + if (!text_provided or output_directory.has_value()) + outputFileContent( + (not output_directory.has_value() ? filesystem::path(file_path.value()) + : output_directory->append( + (not text_provided) ? file_path->filename().string() : to_string(index)) + ).replace_extension(target).string(), resultingPair.first); } catch (const Yerbacon::Exception& error) { resultingPair.first = file_path.has_value() ? file_path->filename().string() : string(); resultingPair.second.emplace(error);