This repository was archived by the owner on Dec 8, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcliParser.go
More file actions
87 lines (69 loc) · 2.01 KB
/
cliParser.go
File metadata and controls
87 lines (69 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import (
"fmt"
"github.com/akamensky/argparse"
"os"
"path"
)
func parseCommandLineArgs() (ArgsParserResult, bool) {
parser := argparse.NewParser("node", "ProgpJS impersonate for NodeJs compatibility")
paramVersion := parser.Flag("v", "version", &argparse.Options{
Required: false,
Help: "Show the version number",
})
paramInspect := parser.Flag("", "inspect", &argparse.Options{
Required: false,
Help: "Enabled the debugger",
Validate: func(args []string) error {
// Allows extracting params if doing "--inspect=options".
// Here "options" is returned, event if there is something after.
//
return nil
},
})
paramDebug := parser.Flag("", "debug", &argparse.Options{
Required: false,
Help: "Enabled the debugger",
})
paramInspectBreak := parser.Flag("", "inspect-brk", &argparse.Options{
Required: false,
Help: "Enabled the debugger",
})
paramScriptToRun := parser.StringPositional(&argparse.Options{Required: false})
// **********************************
// **********************************
// **********************************
err := parser.Parse(os.Args)
if err != nil {
fmt.Print(parser.Usage(err))
return ArgsParserResult{}, false
}
if *paramVersion {
_, _ = fmt.Fprint(os.Stdout, "50.50.50\n")
return ArgsParserResult{}, true
}
scriptToRun := *paramScriptToRun
if scriptToRun == "" {
scriptToRun = "index.js"
}
mustDebug := false
cwd, _ := os.Getwd()
if !path.IsAbs(scriptToRun) {
scriptToRun = path.Join(cwd, scriptToRun)
}
if *paramInspect || *paramInspectBreak || *paramDebug {
// Note: for jetbrains IDE, a environnement variable is set.
// Ex: NODE_OPTIONS=--require /Applications/PhpStorm.app/Contents/plugins/javascript-debugger/debugConnector.js
// It will directly use the "inspect" package, which isn't supported today.
//
mustDebug = true
}
return ArgsParserResult{
Debug: mustDebug,
ScriptToRun: scriptToRun,
}, false
}
type ArgsParserResult struct {
Debug bool
ScriptToRun string
}