Skip to content

Commit

Permalink
Merge pull request #12 from conclurer/master
Browse files Browse the repository at this point in the history
Added second name and flag parsing as false to Flag
  • Loading branch information
kylef committed Nov 6, 2015
2 parents 1fde582 + 217b918 commit d33fbdb
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions Commander/ArgumentDescription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,19 +151,23 @@ public class Flag : ArgumentDescriptor {

public let name:String
public let flag:Character?
public let disabledName:String
public let disabledFlag:Character?
public let description:String?
public let `default`:ValueType
public var type:ArgumentType { return .Option }

public init(_ name:String, flag:Character? = nil, description:String? = nil, `default`:Bool = false) {
public init(_ name:String, flag:Character? = nil, disabledName:String? = nil, disabledFlag:Character? = nil, description:String? = nil, `default`:Bool = false) {
self.name = name
self.disabledName = disabledName ?? "no-\(name)"
self.flag = flag
self.disabledFlag = disabledFlag
self.description = description
self.`default` = `default`
}

public func parse(parser:ArgumentParser) throws -> ValueType {
if parser.hasOption("no-\(name)") {
if parser.hasOption(disabledName) {
return false
}

Expand All @@ -176,6 +180,11 @@ public class Flag : ArgumentDescriptor {
return true
}
}
if let disabledFlag = disabledFlag {
if parser.hasFlag(disabledFlag) {
return false
}
}

return `default`
}
Expand Down

0 comments on commit d33fbdb

Please sign in to comment.