Api to add commands
nsomar opened this issue · comments
Omar Abdelhafith commented
The current API works like this:
- create sub command1
- create sub command2
- create super command that contains 1 and 2
- call execute on this super command
Looks like this:
let show = try! Command(
name: "show",
flags: [
Flag(longName: "foo", value: "-", inheritable: false),
Flag(longName: "bar", value: "-", inheritable: false),
Flag(longName: "yy", value: true, inheritable: false),
],
commands: []) { flags, args in
print("Running git with \(flags) and \(args)")
}
let remote = try! Command(
name: "remote",
flags: [
Flag(longName: "foo", value: "-", inheritable: true),
Flag(longName: "remote", value: true, inheritable: true),
Flag(longName: "bar", value: "-", inheritable: false),
Flag(longName: "xx", value: true, inheritable: false),
],
commands: [show]) { flags, args in
print("Running git with \(flags) and \(args)")
}
let rebase = try! Command(
name: "rebase",
flags: [
Flag(longName: "varvar", value: false, shortName: "v", inheritable: true),
],
commands: []) { flags, args in
print("Running git with \(flags) and \(args)")
}
let git = try! Command(
name: "git",
flags: [
Flag(longName: "debug", type: Bool.self, required: true),
Flag(longName: "verbose", value: false, shortName: "v", inheritable: true),
Flag(longName: "togge", value: false, shortName: "t", inheritable: false),
Flag(longName: "root", value: 1, shortName: "r", inheritable: false),
],
commands: [rebase, remote]) { flags, args in
print("Running git with \(flags) and \(args)")
}
It looks like we need to do the opposite, start from sub, and then implement super, which is opposite of the way of thinking,
The main constraint here is that commands array now its immutable. It has to change to mutable to accomodate the generator process.
Whats your idea on this @goyox86