@@ -22,7 +22,7 @@ const (
2222 CmdTest = "test"
2323 CmdVersion = "version"
2424 CmdTool = "tool"
25- CmdJulenv = "julenv "
25+ CmdEnv = "env "
2626 CmdMod = "mod"
2727)
2828
@@ -33,21 +33,15 @@ let HelpMap: [...][2]str = [
3333 [CmdTest, "Compiles a test program"],
3434 [CmdVersion, "Show version"],
3535 [CmdTool, "Tools for effective Jule"],
36- [CmdJulenv , "Show information about native jule environment"],
36+ [CmdEnv , "Show information about jule environment"],
3737 [CmdMod, "Module management"],
3838]
3939
4040fn printErrorMessage(msg: str) {
4141 println(msg)
4242}
4343
44- // Command: julec help
45- fn help(args: []str, pan: int) {
46- if len(args) > 2 {
47- printErrorMessage("invalid command: " + args[2])
48- ret
49- }
50-
44+ fn writeCommandsList(mut &s: *strings::Builder, pads: str, pad: int) {
5145 mut max := len(HelpMap[0][0])
5246 for _, k in HelpMap {
5347 n := len(k[0])
@@ -56,19 +50,175 @@ fn help(args: []str, pan: int) {
5650 }
5751 }
5852
59- mut s := strings::Builder{}
60- s.Grow(1 << 5)
61- const Space = 5 // Space of between command name and description.
62- for i, part in HelpMap {
63- s.WriteStr(strings::Repeat(" ", pan))!
53+ const Space = 3 // Space of between command name and description.
54+ for _, part in HelpMap {
55+ s.WriteStr(strings::Repeat(pads, pad))!
6456 s.WriteStr(part[0])!
6557 s.WriteStr(strings::Repeat(" ", (max-len(part[0]))+Space))!
6658 s.WriteStr(part[1])!
67- if i+1 < len(HelpMap) {
68- s.WriteByte('\n')!
59+ s.WriteByte('\n')!
60+ }
61+ }
62+
63+ // Command: julec help
64+ fn help(args: []str, pads: str, pad: int) {
65+ if len(args) == 2 { // julec help
66+ mut max := len(HelpMap[0][0])
67+ for _, k in HelpMap {
68+ n := len(k[0])
69+ if n > max {
70+ max = n
71+ }
6972 }
73+
74+ mut s := strings::Builder{}
75+ s.WriteStr("The help command shows information about the julec tool and commands.\n\nThe commands are:\n")!
76+ writeCommandsList(&s, pads, pad)
77+ s.WriteByte('\n')!
78+ s.WriteStr(`Use "julec help <command>" to see information about a command.`)!
79+ println(s.Str())
80+ ret
81+ }
82+ if len(args) > 3 { // julec help <command> [unknown]
83+ printErrorMessage("invalid command: " + args[3])
84+ ret
85+ }
86+ // julec help <command>
87+ command := args[2]
88+ match command {
89+ | CmdHelp:
90+ println(`The help command shows information about the julec tool and commands.
91+
92+ julec help Show the general help information about the julec tool
93+ julec help <command> Show the information about a command`)
94+ | CmdBuild:
95+ println(`The build command compiles the packages named by the import paths.
96+
97+ Usage:
98+ julec build [arguments] <path>
99+
100+ The compile path must be the main package directory of the program.
101+ When compiling packages, build ignores files that end in '_test.jule'.
102+ The main package must have the entry point "main" function.
103+
104+ The most common arguments are:
105+ -t --tranpile
106+ Enables transpilation mode.
107+ Code will be compiled to IR but object file will not be created.
108+ It may be useful for debugging.
109+ -o --out <path>
110+ Forces build to write the resulting executable file to the named output file.
111+ It is "main" by default (with ".exe" extension on Windows).
112+ On Windows, the ".exe" extension will be appended for executable files if
113+ path is not have the extension.
114+ -p --production
115+ Enables production compilation.
116+ Compiles for production build, not recommended for debug compilations.
117+ It may increase compilation time significantly but will improve performance.
118+ --opt <level>
119+ Enables optimizations. It uses L0 by default.
120+ Levels are L0, L1, and L2. For debug compilations, L0 is recommended.
121+ Every level enables all optimizations of the previous levels.
122+ --compiler <value>
123+ Selects the back-end compiler standard. It uses "clang" by default.
124+ Supported values are "clang" for Clang and "gcc" for GNU Compiler Collection.
125+ Recommended compiler is the Clang.
126+ --compiler-path <path>
127+ The path of the back-end compiler. It uses "clang++" for Clang and "g++" for GCC.
128+ If the back-end compiler path is not different, this option is not
129+ requires extra attention. Setting with the [--compiler] option is enough.
130+ --target <target>
131+ Changes the target of the build. The default value is "native-native".
132+ Value format is <os>-<arch>, like darwin-arm64 or linux-amd64.
133+ This will not be used by the back-end compiler. It will enables target
134+ architecture imititation and IR will be generated accordingly.
135+ But it will be compiled with your native target.
136+ Use the "julec tool targets" to see valid targets.
137+ The value "native-native" equals to your native target.`)
138+ | CmdTest:
139+ println(`The test command compiles the packages named by the import paths for testing.
140+
141+ Usage:
142+ julec test [arguments] <path>
143+
144+ The compile path must be the package directory of the program to be tested.
145+ When compiling packages for testing, it will include files that end in '_test.jule'.
146+ The package may have not the entry point "main" function, it will not be used.
147+ Test compilations uses implicitly generated entry point for testing.
148+
149+ The most common arguments are:
150+ -t --tranpile
151+ Enables transpilation mode.
152+ Code will be compiled to IR but object file will not be created.
153+ It may be useful for debugging.
154+ -o --out <path>
155+ Forces build to write the resulting executable file to the named output file.
156+ It is "main" by default (with ".exe" extension on Windows).
157+ On Windows, the ".exe" extension will be appended for executable files if
158+ path is not have the extension.
159+ -p --production
160+ Enables production compilation.
161+ Compiles for production build, not recommended for debug compilations.
162+ It may increase compilation time significantly but will improve performance.
163+ --opt <level>
164+ Enables optimizations. It uses L0 by default.
165+ Levels are L0, L1, and L2. For debug compilations, L0 is recommended.
166+ Every level enables all optimizations of the previous levels.
167+ --compiler <value>
168+ Selects the back-end compiler standard. It uses "clang" by default.
169+ Supported values are "clang" for Clang and "gcc" for GNU Compiler Collection.
170+ Recommended compiler is the Clang.
171+ --compiler-path <path>
172+ The path of the back-end compiler. It uses "clang++" for Clang and "g++" for GCC.
173+ If the back-end compiler path is not different, this option is not
174+ requires extra attention. Setting with the [--compiler] option is enough.
175+ --target <target>
176+ Changes the target of the build. The default value is "native-native".
177+ Value format is <os>-<arch>, like darwin-arm64 or linux-amd64.
178+ This will not be used by the back-end compiler. It will enables target
179+ architecture imititation and IR will be generated accordingly.
180+ But it will be compiled with your native target.
181+ Use the "julec tool targets" to see valid targets.
182+ The value "native-native" equals to your native target.`)
183+ | CmdMod:
184+ println(`The mod command is a tool managing your jule modules.
185+
186+ Usage:
187+ julec mod <command>
188+
189+ The commands are:` + modCommandsList + `
190+
191+ Modules Names
192+ A module name may only consist of letters, digits, '_', or '.' characters.
193+ The first character must be either a letter or an '_'.
194+ `)
195+ | CmdVersion:
196+ println(`The version command shows your julec tool version.
197+
198+ Usage:
199+ julec version
200+
201+ This is the version of the julec tool, standard library and API.`)
202+ | CmdTool:
203+ println(`The tool command provides several minimal tools for the Jule programming language.
204+
205+ Usage:
206+ julec tool <tool>
207+
208+ With no arguments it prints the list of known tools.
209+
210+ The tools are:` + toolsList)
211+ | CmdEnv:
212+ println(`The env command provides information about your jule environment.
213+
214+ Usage:
215+ julec env
216+
217+ It shows information about your native jule environment.`)
218+ |:
219+ printErrorMessage("invalid command: " + command + `
220+ write "julec help" to see commands`)
70221 }
71- println(s.Str())
72222}
73223
74224// Command: julec version
@@ -112,13 +262,15 @@ fn toolDistarch() {
112262 println("")
113263}
114264
265+ const toolsList = `
266+ targets List all supported target pairs
267+ distos List all supported operating systems
268+ distarch List all supported architects`
269+
115270// Command: julec tool
116271fn tool(args: []str) {
117272 if len(args) == 2 {
118- println(`tool commands:
119- targets List all supported target pairs
120- distos List all supported operating systems
121- distarch List all supported architects`)
273+ println("The tools are:" + toolsList)
122274 ret
123275 } else if len(args) > 3 {
124276 printErrorMessage("invalid command: " + args[3])
@@ -138,8 +290,8 @@ fn tool(args: []str) {
138290 }
139291}
140292
141- // Command: julec julenv
142- fn julenv (args: []str) {
293+ // Command: julec env
294+ fn env (args: []str) {
143295 if len(args) > 2 {
144296 printErrorMessage("invalid command: " + args[2])
145297 ret
@@ -151,10 +303,15 @@ fn julenv(args: []str) {
151303 println("default C++ standard: " + env::CppStd)
152304}
153305
306+ const modCommandsList = `
307+ init <modulename> Initializes a new module in the current path`
308+
154309// Command: julec mod
155310fn mod(args: []str) {
156311 if len(args) == 2 {
157- println("no command given, try julec mod init")
312+ println(`julec mod is a tool for managing Jule modules.
313+
314+ The commands are:` + modCommandsList)
158315 ret
159316 }
160317
@@ -194,15 +351,15 @@ fn mod(args: []str) {
194351fn processCommand(mut args: []str) {
195352 match args[1] {
196353 | CmdHelp:
197- help(args, 0 )
354+ help(args, "\t", 1 )
198355 | CmdBuild | CmdTest:
199356 build(args)
200357 | CmdVersion:
201358 version(args)
202359 | CmdTool:
203360 tool(args)
204- | CmdJulenv :
205- julenv (args)
361+ | CmdEnv :
362+ env (args)
206363 | CmdMod:
207364 mod(args)
208365 |:
@@ -212,13 +369,20 @@ fn processCommand(mut args: []str) {
212369
213370fn showInfo(args: []str) {
214371 println(
215- `JuleC is the Jule programming language compiler.
372+ `JuleC is a tool for managing Jule source code.
373+
374+ Usage:
375+ julec <command> [arguments]
216376
217- Commands:`)
218- help(args, 4)
377+ The commands are:`)
378+ mut s := strings::Builder{}
379+ writeCommandsList(&s, "\t", 1)
380+ print(s.Str())
219381 println(`
382+ Use "julec help <command>" for more information about a command.
383+
220384Compilation:
221- julec [OPTIONS] INPUT `)
385+ julec build [arguments] <path> `)
222386}
223387
224388fn init() {
0 commit comments