Skip to content

Commit

Permalink
[CLI] Introduce Arguments Parsing Engine #37
Browse files Browse the repository at this point in the history
  • Loading branch information
PeyTy committed May 1, 2023
1 parent 8950e02 commit 8413e9b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
1 change: 1 addition & 0 deletions hexa.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"data/compilerError",
"data/hints",
"targets",
"cli/args",
"cli/help",
"repl",
"main",
Expand Down
10 changes: 2 additions & 8 deletions source/cli.hexa
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
40 changes: 40 additions & 0 deletions source/cli/args.hexa
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.

/// 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()
}
}

0 comments on commit 8413e9b

Please sign in to comment.