Skip to content

Commit 1d4b125

Browse files
committed
Cleanup hack to process flags in add command
Rather than have the add command hack in support for optional values to flags make it a core feature of `ELCLI`. That seems like the proper place to handle this situation and also doesn't break existing functionality/assumptions in all the other uses/tests.
1 parent 125e682 commit 1d4b125

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

Modules/ELCLI/ELCLI/CLI.swift

+14-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,20 @@ open class CLI {
154154
// it's a "--flag value" type argument.
155155
if index < arguments.count - 1 {
156156
value = arguments[index + 1]
157-
skipNext = true
157+
// If we're assuming `--flag value` make sure
158+
// our `value` isn't a stop marker or flag. If it is
159+
// our value should instead be `nil`'d out so our
160+
// command does not get a value where it is our next
161+
// argument.
162+
if let argValue = value,
163+
isStopMarker(argValue) || isFlag(argValue) {
164+
value = nil
165+
} else {
166+
// However if that's not the case we should skip
167+
// the next command because we really did get
168+
// `--flag value`
169+
skipNext = true
170+
}
158171
}
159172
}
160173
}

ModuloKit/Commands/AddCommand.swift

+1-15
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,7 @@ open class AddCommand: NSObject, Command {
4444

4545
addOptionValue(["--unmanaged"], usage: "specifies that this module will be unmanaged", valueSignature: "<[hash|branch|nothing]>") { (option, value) -> Void in
4646
self.unmanaged = true
47-
if let value = value {
48-
if !value.hasPrefix("-") {
49-
self.unmanagedValue = value
50-
} else {
51-
if self.verbose {
52-
writeln(.stderr, "Assuming '\(value)' is a flag and not a branch/commit hash since it begins with '-' and will not track it.")
53-
}
54-
// TODO: Somehow reprocess this `value` as a flag
55-
self.options.filter({ (option) -> Bool in
56-
option.flags?.contains(value) ?? false
57-
}).forEach({ (option) in
58-
option.closure(value, nil)
59-
})
60-
}
61-
}
47+
self.unmanagedValue = value
6248
}
6349

6450
addOption(["-u", "--update"], usage: "performs the update command after adding a module") { (option, value) in

0 commit comments

Comments
 (0)