-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor to use context * refactor to use context * readme updated * refactor command parsing * refactor command parsing * update changelog * fix tests
- Loading branch information
1 parent
d178090
commit f7289f2
Showing
22 changed files
with
2,123 additions
and
412 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
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
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 |
---|---|---|
@@ -1,57 +1,61 @@ | ||
from memory import Arc | ||
from prism import Command, CommandArc, no_args, valid_args, minimum_n_args, maximum_n_args, exact_args, range_args | ||
|
||
|
||
fn test(inout command: Arc[Command], args: List[String]) -> None: | ||
for arg in args: | ||
from prism import ( | ||
Command, | ||
Context, | ||
CommandArc, | ||
no_args, | ||
valid_args, | ||
minimum_n_args, | ||
maximum_n_args, | ||
exact_args, | ||
range_args, | ||
) | ||
|
||
|
||
fn test(context: Context) -> None: | ||
for arg in context.args: | ||
print("Received", arg[]) | ||
|
||
|
||
fn hello(inout command: Arc[Command], args: List[String]) -> None: | ||
print(command[].name, "Hello from Chromeria!") | ||
fn hello(context: Context) -> None: | ||
print(context.command[].name, "Hello from Chromeria!") | ||
|
||
|
||
fn main() -> None: | ||
var root = Arc( | ||
Command( | ||
name="hello", | ||
description="This is a dummy command!", | ||
run=test, | ||
) | ||
var root = Command( | ||
name="hello", | ||
description="This is a dummy command!", | ||
run=test, | ||
) | ||
|
||
var no_args_command = Arc( | ||
Command(name="no_args", description="This is a dummy command!", run=hello, arg_validator=no_args) | ||
) | ||
var no_args_command = Arc(Command(name="no_args", description="This is a dummy command!", run=hello)) | ||
no_args_command[].arg_validator = no_args | ||
|
||
var valid_args_command = Arc( | ||
Command( | ||
name="valid_args", | ||
description="This is a dummy command!", | ||
run=hello, | ||
arg_validator=valid_args(), | ||
) | ||
) | ||
var minimum_n_args_command = Arc( | ||
Command( | ||
name="minimum_n_args", description="This is a dummy command!", run=hello, arg_validator=minimum_n_args[4]() | ||
) | ||
) | ||
var maximum_n_args_command = Arc( | ||
Command( | ||
name="maximum_n_args", description="This is a dummy command!", run=hello, arg_validator=maximum_n_args[1]() | ||
) | ||
) | ||
var exact_args_command = Arc( | ||
Command(name="exact_args", description="This is a dummy command!", run=hello, arg_validator=exact_args[1]()) | ||
) | ||
var range_args_command = Arc( | ||
Command(name="range_args", description="This is a dummy command!", run=hello, arg_validator=range_args[0, 1]()) | ||
) | ||
valid_args_command[].arg_validator = valid_args | ||
|
||
var minimum_n_args_command = Arc(Command(name="minimum_n_args", description="This is a dummy command!", run=hello)) | ||
minimum_n_args_command[].arg_validator = minimum_n_args[4]() | ||
|
||
var maximum_n_args_command = Arc(Command(name="maximum_n_args", description="This is a dummy command!", run=hello)) | ||
maximum_n_args_command[].arg_validator = maximum_n_args[1]() | ||
|
||
var exact_args_command = Arc(Command(name="exact_args", description="This is a dummy command!", run=hello)) | ||
exact_args_command[].arg_validator = exact_args[1]() | ||
|
||
var range_args_command = Arc(Command(name="range_args", description="This is a dummy command!", run=hello)) | ||
range_args_command[].arg_validator = range_args[0, 1]() | ||
|
||
root[].add_subcommand(no_args_command) | ||
root[].add_subcommand(valid_args_command) | ||
root[].add_subcommand(minimum_n_args_command) | ||
root[].add_subcommand(maximum_n_args_command) | ||
root[].add_subcommand(exact_args_command) | ||
root[].add_subcommand(range_args_command) | ||
root[].execute() | ||
root.add_subcommand(no_args_command) | ||
root.add_subcommand(valid_args_command) | ||
root.add_subcommand(minimum_n_args_command) | ||
root.add_subcommand(maximum_n_args_command) | ||
root.add_subcommand(exact_args_command) | ||
root.add_subcommand(range_args_command) | ||
root.execute() |
Oops, something went wrong.