Skip to content

Commit

Permalink
Fix for storage of multi-case auth token. Less spacing on top-level h…
Browse files Browse the repository at this point in the history
…elp text.
  • Loading branch information
ptsochantaris committed May 18, 2021
1 parent 9a33a29 commit 1df37c7
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 16 deletions.
10 changes: 0 additions & 10 deletions Sources/trailer/Actions/Actions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -246,30 +246,20 @@ struct Actions {
printOptionHeader("ACTION can be one of the following:")
log()
printOption(name: "update", description: "(Re)load local cache from GitHub. Specify 'help' for more info.")
log()
printOption(name: "list", description: "List or search for various items. Specify 'help' for more info.")
log()
printOption(name: "show", description: "Display details of specific items. Specify 'help' for more info.")
log()
printOption(name: "open", description: "Open the specific item in a web browser. If multiple items match, the first one opens. Specify 'help' for more info.")
log()
printOption(name: "config", description: "Visibility options for repositories. Specify 'help' for more info.")
log()
printOption(name: "stats", description: "List stats on stored data.")
log()
printOption(name: "reset", description: "Clear all stored data, including config/token.")
log()

printOptionHeader("Advanced options:")
log()
printOption(name: "-server <URL>", description: "Full URL to the API endpoint of the GitHub server you want to query. Defaults to 'https://api.github.com/graphql'.")
log()
printOption(name: "-token <token>", description: "Auth API token to use when accessing the default or selected server. The value given here is persisted and doesn't need to be repeated. '-token display' shows the stored token. '-token test' tests the stored token.")
log()
printOption(name: "-v / -debug", description: "Enable verbose output, -debug provides a debug trace.")
log()
printOption(name: "-page-size", description: "Minimum items fetched per API call (default: 50). If you get errors about queries failing, reduce this to a lower value. Must be between 10 and 100.")
log()
printOption(name: "-mono", description: "Generate monochrome text output.")
log()

Expand Down
4 changes: 2 additions & 2 deletions Sources/trailer/Core/CommandLine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ private let _args = CommandLine.arguments.map { $0.lowercased() }

extension CommandLine {

static func value(for argument: String) -> String? {
static func value(for argument: String, keepCase: Bool = false) -> String? {
guard let index = _args.firstIndex(of: argument) else { return nil }

let valueIndex = index + 1
if _args.count > valueIndex {
let nextArg = _args[valueIndex]
let nextArg = keepCase ? CommandLine.arguments[valueIndex] : _args[valueIndex]
if nextArg.hasPrefix("-") {
return ""
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/trailer/Core/Config.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct Config {

let versionMajor = 1
let versionMinor = 1
let versionPatch = 1
let versionPatch = 2
var versionString: String {
return [versionMajor, versionMinor, versionPatch].map { String($0) }.joined(separator: ".")
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/trailer/Core/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ private func go() {
if actionDetected == nil {
exit(0)
}
} else {
config.token = t
log("Token for server [*\(config.server.absoluteString)*] has been set to [*\(t)*]")
} else if let token = CommandLine.value(for: "-token", keepCase: true) {
config.token = token
log("Token for server [*\(config.server.absoluteString)*] has been set to [*\(token)*]")
if actionDetected == nil {
exit(0)
}
Expand Down

0 comments on commit 1df37c7

Please sign in to comment.