Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
7d504b5
feat: argparse
peter-jerry-ye Feb 6, 2026
044992f
fix: clap parity
peter-jerry-ye Feb 10, 2026
01a0e80
refactor: build the command group in advance
FlyCloudC Feb 11, 2026
ce94f86
refactor: one source per match
peter-jerry-ye Feb 13, 2026
8e16b0c
fix: validation
peter-jerry-ye Feb 14, 2026
7de9550
refactor: reorganize Arg struct fields for clarity
FlyCloudC Feb 25, 2026
fd9fb13
refactor: unify Arg struct fields under ArgInfo for improved clarity …
FlyCloudC Feb 25, 2026
1e67004
refactor: direct checks on Arg info
FlyCloudC Feb 25, 2026
6cc3681
refactor: replace arg_action usage with direct checks on Arg info for…
FlyCloudC Feb 25, 2026
55ada3b
simplify
FlyCloudC Feb 25, 2026
03195d3
refactor: remove last field from OptionArg
FlyCloudC Feb 25, 2026
ab87ca7
chore: cleanup code
peter-jerry-ye Feb 26, 2026
9a052ca
fix: use `*view` types
peter-jerry-ye Feb 26, 2026
6dccaa1
fix: handle review
peter-jerry-ye Feb 26, 2026
a238e5c
refactor: separate argument config and remove &Arg
peter-jerry-ye Feb 26, 2026
93454f2
Fix global override merge edge cases in argparse
peter-jerry-ye Feb 27, 2026
e530896
fix(argparse): infer positional indices for mixed positionals
peter-jerry-ye Feb 27, 2026
e32633e
add debug support
bobzhang Feb 28, 2026
ef634b0
add some comments
bobzhang Feb 28, 2026
e8b31f1
feat(argparse): add help-exit runtime and restore snapshots
peter-jerry-ye Feb 28, 2026
6ae1070
fix(argparse): include parent path in subcommand help output
peter-jerry-ye Feb 28, 2026
dceb587
fix(argparse): include requires source in missing argument errors
peter-jerry-ye Feb 28, 2026
1a8c2b0
refactor(argparse): rename arg constructors to Flag/Option/Positional
peter-jerry-ye Mar 2, 2026
d304585
fix(argparse): keep group usage hints in error line only
peter-jerry-ye Mar 2, 2026
51dbd0f
fix(argparse): drop positional required markers from help args section
peter-jerry-ye Mar 2, 2026
24d72a9
docs(argparse): reorganize README usage sections
peter-jerry-ye Mar 2, 2026
4fb2433
refactor(argparse): remove positional required and last options
peter-jerry-ye Mar 2, 2026
f910fab
docs(argparse): add positional passthrough separator examples
peter-jerry-ye Mar 2, 2026
380f3f5
test(argparse): remove unreachable panic branches and clean README ex…
peter-jerry-ye Mar 2, 2026
8a79e13
chore: cleanup
peter-jerry-ye Mar 2, 2026
e65270c
doc(argparse): improve error message
peter-jerry-ye Mar 2, 2026
fb9fe6b
feat(argparse): render help metadata and group flags as tags
peter-jerry-ye Mar 2, 2026
f22d01c
doc(argparse): improve doc comments
peter-jerry-ye Mar 2, 2026
74d2844
refactor(argparse): cleanup validation errors and parser internals
peter-jerry-ye Mar 2, 2026
a1c5b18
fix(argparse): honor global overrides across subcommand parsing
peter-jerry-ye Mar 2, 2026
49b58a6
fix(argparse): handle ffi and code review
peter-jerry-ye Mar 2, 2026
2c4a689
change Option to Optional
bobzhang Mar 3, 2026
82a70ff
`moon info`
bobzhang Mar 3, 2026
955d20e
refactor(argparse): hide ArgError and raise generic parse errors
peter-jerry-ye Mar 3, 2026
58eab64
refactor(argparse): rename constructors to *Arg forms
peter-jerry-ye Mar 3, 2026
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
544 changes: 544 additions & 0 deletions argparse/README.mbt.md

Large diffs are not rendered by default.

44 changes: 44 additions & 0 deletions argparse/arg_action.mbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2026 International Digital Economy Academy
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

///|
fn arg_min_max_for_validate(arg : Arg) -> (Int, Int?) raise ArgBuildError {
if arg.info is PositionalInfo(num_args=Some(range), ..) {
if range.lower < 0 {
raise Unsupported("min values must be >= 0")
}
if range.upper is Some(max_value) {
if max_value < 0 {
raise Unsupported("max values must be >= 0")
}
if max_value < range.lower {
raise Unsupported("max values must be >= min values")
}
if range.lower == 0 && max_value == 0 {
raise Unsupported("empty value range (0..0) is unsupported")
}
}
(range.lower, range.upper)
} else {
(0, None)
}
}

///|
fn arg_min_max(arg : Arg) -> (Int, Int?) {
match arg.info {
PositionalInfo(num_args=Some(range), ..) => (range.lower, range.upper)
_ => (0, None)
}
}
60 changes: 60 additions & 0 deletions argparse/arg_group.mbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright 2026 International Digital Economy Academy
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

///|
/// Declarative argument group constructor.
pub struct ArgGroup {
priv name : String
priv required : Bool
priv multiple : Bool
priv args : Array[String]
priv requires : Array[String]
priv conflicts_with : Array[String]

/// Create an argument group.
fn new(
name : StringView,
required? : Bool,
multiple? : Bool,
args? : ArrayView[String],
requires? : ArrayView[String],
conflicts_with? : ArrayView[String],
) -> ArgGroup
}

///|
/// Create an argument group.
///
/// Notes:
/// - `required=true` means at least one member of the group must be present.
/// - `multiple=false` means group members are mutually exclusive.
/// - `requires` and `conflicts_with` may reference either group names or
/// argument names.
pub fn ArgGroup::new(
name : StringView,
required? : Bool = false,
multiple? : Bool = true,
args? : ArrayView[String] = [],
requires? : ArrayView[String] = [],
conflicts_with? : ArrayView[String] = [],
) -> ArgGroup {
{
name: name.to_string(),
required,
multiple,
args: args.to_array(),
requires: requires.to_array(),
conflicts_with: conflicts_with.to_array(),
}
}
Loading