-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CLI] Introduce Arguments Parsing Engine #37
- Loading branch information
Showing
3 changed files
with
43 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ | |
"data/compilerError", | ||
"data/hints", | ||
"targets", | ||
"cli/args", | ||
"cli/help", | ||
"repl", | ||
"main", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |