From 1df37c7811cd09a3fd6b52a6f43c874b232a7a4f Mon Sep 17 00:00:00 2001 From: Paul Tsochantaris Date: Tue, 18 May 2021 22:49:48 +0100 Subject: [PATCH] Fix for storage of multi-case auth token. Less spacing on top-level help text. --- Sources/trailer/Actions/Actions.swift | 10 ---------- Sources/trailer/Core/CommandLine.swift | 4 ++-- Sources/trailer/Core/Config.swift | 2 +- Sources/trailer/Core/main.swift | 6 +++--- 4 files changed, 6 insertions(+), 16 deletions(-) diff --git a/Sources/trailer/Actions/Actions.swift b/Sources/trailer/Actions/Actions.swift index cd535ef..6a99a43 100644 --- a/Sources/trailer/Actions/Actions.swift +++ b/Sources/trailer/Actions/Actions.swift @@ -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 ", 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 ", 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() diff --git a/Sources/trailer/Core/CommandLine.swift b/Sources/trailer/Core/CommandLine.swift index 8b83421..300b0d8 100644 --- a/Sources/trailer/Core/CommandLine.swift +++ b/Sources/trailer/Core/CommandLine.swift @@ -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 "" } diff --git a/Sources/trailer/Core/Config.swift b/Sources/trailer/Core/Config.swift index aa30845..0cde849 100644 --- a/Sources/trailer/Core/Config.swift +++ b/Sources/trailer/Core/Config.swift @@ -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: ".") } diff --git a/Sources/trailer/Core/main.swift b/Sources/trailer/Core/main.swift index 1907bd6..50b470a 100644 --- a/Sources/trailer/Core/main.swift +++ b/Sources/trailer/Core/main.swift @@ -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) }