diff --git a/hexa.json b/hexa.json index 07041d0..baf752b 100644 --- a/hexa.json +++ b/hexa.json @@ -27,6 +27,7 @@ "data/compilerError", "data/hints", "targets", + "cli/args", "cli/help", "repl", "main", diff --git a/source/cli.hexa b/source/cli.hexa index de4cc64..06b9d27 100644 --- a/source/cli.hexa +++ b/source/cli.hexa @@ -1,5 +1,5 @@ // The Hexa Compiler -// Copyright (C) 2021-2022 Oleh Petrenko +// Copyright (C) 2021-2023 Oleh Petrenko // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as published by @@ -17,13 +17,7 @@ // Pre-parse command line arguments and decide what to do { - // Cleanup argv - if process.argv[0].endsWith('node.exe') || process.argv[0].endsWith('node') { - process.argv.shift() - process.argv.shift() - } else if process.argv[0].endsWith(/*hexa*/'.exe') { - process.argv.shift() - } + ArgumentsParsingEngine.engage() // Entry point // TODO support `ignoreArguments` feature here diff --git a/source/cli/args.hexa b/source/cli/args.hexa new file mode 100644 index 0000000..d6a4646 --- /dev/null +++ b/source/cli/args.hexa @@ -0,0 +1,40 @@ +// The Hexa Compiler +// Copyright (C) 2023 Oleh Petrenko +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . + +/// Ignores some parts like leading .exe and .js +class ArgumentsParsingEngine { + + /// Do this before any parsing + static fun cleanupArgv() { + if process.argv[0].endsWith('node.exe') || process.argv[0].endsWith('node') { + process.argv.shift() + // The second one is .js file + process.argv.shift() + } else if process.argv[0].endsWith(/*hexa*/'.exe') { + process.argv.shift() + // TODO should be null-guarded after null-checks of `[]` enabled + // `process.argv?[0].endsWith('.js')` + if process.argv[0] != null, process.argv[0].endsWith('.js') { + // The second one is .js file when bundled wih N-EXE + process.argv.shift() + } + } + } + + /// Entry point + static fun engage() { + cleanupArgv() + } +}