Skip to content

Commit

Permalink
generated help flag inserted first.
Browse files Browse the repository at this point in the history
  • Loading branch information
dastrobu committed May 3, 2018
1 parent 81f39b1 commit d37e9d5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,13 @@ flags:
```

##### Parse Order
The generated help flag is always added before the first [Var Args](#varargs) parser (which should usually be last), or as last parser, if there is no var args parser.
This ensures parse order plays together with var args nicely.
The generated help flag is always added as first parser to make sure it plays together with
[Var Args](#varargs) nicely.
The order of the parsers can be changed after creation of the `ArgTree` object by manipulating its elements via the
`MutableCollection` protocol (like an array). For example, to move the auto generated help flag parser to the end, do:
```swift
var argTree = ArgTree(description: "foo")

let help = a.remove(at: a.index(where: {$0 is Help})!) // find help
a.append(help) // add it at the end
argTree.append(argTree.removeFirst())
```

##### Default Action
Expand Down
6 changes: 2 additions & 4 deletions Sources/ArgTree.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ public class ArgTree: ParserNode {
helpPrinted()
}
// add help as first parse, to play together with the var arg parser
let i = parsers.index(where: { $0 is VarArgs }) ?? 0
insert(Help(longName: "help", shortName: "h", parsed: { _ in writeHelp() }), at: i)
insert(Help(longName: "help", shortName: "h", parsed: { _ in writeHelp() }), at: 0)
defaultAction = writeHelp
}

Expand All @@ -118,8 +117,7 @@ public class ArgTree: ParserNode {
helpPrinted()
}
// add help as first parse, to play together with the var arg parser
let i = parsers.index(where: { $0 is VarArgs }) ?? 0
insert(Help(longName: "help", shortName: "h", parsed: { _ in printHelp() }), at: i)
insert(Help(longName: "help", shortName: "h", parsed: { _ in printHelp() }), at: 0)
defaultAction = printHelp
}

Expand Down

0 comments on commit d37e9d5

Please sign in to comment.