Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compiler: improve consistency in julec and julec help #122

Merged
merged 1 commit into from
Jan 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 15 additions & 19 deletions src/julec/main.jule
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const CmdMod = "mod"

// Map for "julec help" command.
static HelpMap: [...][2]str = [
[CmdHelp, "Show help"],
[CmdHelp, "Show the list of available commands"],
[CmdVersion, "Show version"],
[CmdTool, "Tools for effective Jule"],
[CmdJulenv, "Show information about native jule environment"],
Expand All @@ -32,7 +32,7 @@ fn printErrorMessage(msg: str) {
}

// Command: julec help
fn help(&args: []str) {
fn help(&args: []str, pan: int) {
if len(args) > 2 {
printErrorMessage("invalid command: " + args[2])
ret
Expand All @@ -50,6 +50,7 @@ fn help(&args: []str) {
s.Grow(1 << 5)
const Space = 5 // Space of between command name and description.
for i, part in HelpMap {
s.WriteStr(strings::Repeat(" ", pan))!
s.WriteStr(part[0])!
s.WriteStr(strings::Repeat(" ", (max-len(part[0]))+Space))!
s.WriteStr(part[1])!
Expand Down Expand Up @@ -95,8 +96,8 @@ fn toolDistarch() {
fn tool(&args: []str) {
if len(args) == 2 {
println(`tool commands:
distos Lists all supported operating systems
distarch Lists all supported architects`)
distos List all supported operating systems
distarch List all supported architects`)
ret
} else if len(args) > 3 {
printErrorMessage("invalid command: " + args[3])
Expand Down Expand Up @@ -130,7 +131,7 @@ fn julenv(&args: []str) {
// Command: julec mod
fn mod(&args: []str) {
if len(args) == 2 {
println("command is not given, try julec mod init")
println("no command given, try julec mod init")
ret
}

Expand All @@ -142,7 +143,7 @@ fn mod(&args: []str) {
match args[2] {
| "init": // julec mod init
os::File.Write(jule::ModuleFile, [], 0o660) else {
printErrorMessage("module could not generated because of a problem")
printErrorMessage("module could not be generated")
}
|:
printErrorMessage("invalid command: " + args[2])
Expand All @@ -154,7 +155,7 @@ fn mod(&args: []str) {
fn processCommand(&args: []str): bool {
match args[1] {
| CmdHelp:
help(args)
help(args, 0)
| CmdVersion:
version(args)
| CmdTool:
Expand All @@ -170,20 +171,15 @@ fn processCommand(&args: []str): bool {
ret true
}

fn showInfo() {
fn showInfo(args: []str) {
println(
`JuleC is a tool for Jule source code and developers.

Commands:
help Show help
version Show version
tool Tools for effective Jule
julenv Show information about native jule environment
mod Module management
`JuleC is the Jule programming language compiler.

Commands:`)
help(args, 4)
println(`
Compilation:
julec [OPTIONS] INPUT
`)
julec [OPTIONS] INPUT`)
}

fn main() {
Expand All @@ -192,7 +188,7 @@ fn main() {
// Not started with arguments.
// Here is "2" but "args" always have one element for store program name.
if len(args) < 2 {
showInfo()
showInfo(args)
ret
}

Expand Down
Loading