From 15a8f904f880d7099c9575170939e2a51d05121f Mon Sep 17 00:00:00 2001 From: Stephen Martinez Date: Sat, 14 Dec 2019 16:30:58 -0800 Subject: [PATCH 1/4] [CPFeature-005][NewArgument] Updated the readme with new requirements and intallation doc --- README.md | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index baf0414..19c63fe 100644 --- a/README.md +++ b/README.md @@ -20,45 +20,49 @@ The actions that can be done are: * View the current mode and stored prefixes ___ -### -- Installation -- +### -- Requirements -- -1. Clone the repo +This package uses `swift-tools-version:5.1` as a minimum requirement to build and install. +Check to see that you have Swift 5.1 or greater to meet the requirements ```zsh -% git clone https://github.com/enuance/commitPrefix.git +% swift --version ``` -2. Open the Package +Supported OS: +- macOS Catalina v10.15.1 or greater + +___ +### -- Installation -- + +1. Clone the repo and move to the root of the directory ```zsh +% git clone https://github.com/enuance/commitPrefix.git % cd commitPrefix -% open Package.swift ``` -3. Build the executable by pressing **⌘B** or select it from the menu **Product -> Build** - -4. Locate the executable by running this in the terminal +2. *Optional* Run the installer ```zsh -% find ~/Library/Developer/Xcode/DerivedData -name "commitPrefix" +% ./Installer ``` -This command will display all locations where files have the name “commitPrefix” -It should be the one contained in `/Users//Library/Developer/Xcode/DerivedData/commitPrefix-/Build/Products/Release/commitPrefix` - -Make sure not to select ones that have `commitPrefix.dSYM` in it's path +As a good practice, please make sure to read the source code of the installer script before running it. If you do not feel comfortable running the installer, you could manually build and install it instead. If you would like to do so, follow these steps: -5. Open a window at the location by using Finder and selecting **Go -> Go to folder...** enter in the path and select **Go** +2. Build the executable -You can also use the terminal **open** command but you'd have to remove the executable `/commitPrefix` from the end of the path +```zsh +% swift build -c release +``` -6. Open your local executables folder by entering: +3. Install it into the local bin folder ```zsh -% open /usr/local/bin +% mv .build/release/commitPrefix /usr/local/bin ``` -7. Drag and drop the Unix executable `commitPrefix` into you `bin` folder. On your next Terminal session you should be able to see auto-completion and use commitPrefix. +On your next Terminal session you should be able to see auto-completion and use commitPrefix. ___ ### -- Usage -- From 1a546a833afbd87f67780af67d752ed3b1dccb4a Mon Sep 17 00:00:00 2001 From: Stephen Martinez Date: Sat, 14 Dec 2019 16:31:31 -0800 Subject: [PATCH 2/4] [CPFeature-005][NewArgument] Updated the docs on the CPTermination type --- Sources/CommitPrefix/CPError.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/CommitPrefix/CPError.swift b/Sources/CommitPrefix/CPError.swift index 46165da..c92514f 100644 --- a/Sources/CommitPrefix/CPError.swift +++ b/Sources/CommitPrefix/CPError.swift @@ -65,6 +65,7 @@ enum CPError: Error { } +/// An Error Type that should terminate the program if detected enum CPTermination: Error { case overwriteCancelled From c42f0d007340b6e25f2a02f99fe3c42bf6ed1a9d Mon Sep 17 00:00:00 2001 From: Stephen Martinez Date: Sat, 14 Dec 2019 16:32:29 -0800 Subject: [PATCH 3/4] [CPFeature-005][NewArgument] Moved the version to a global constants file --- Sources/CommitPrefix/CommitMessageHook.swift | 4 +--- Sources/CommitPrefix/Constants.swift | 6 ++++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Sources/CommitPrefix/CommitMessageHook.swift b/Sources/CommitPrefix/CommitMessageHook.swift index d427459..4941cc8 100644 --- a/Sources/CommitPrefix/CommitMessageHook.swift +++ b/Sources/CommitPrefix/CommitMessageHook.swift @@ -29,9 +29,7 @@ import Foundation public struct CommitMessageHook { - private static let cpVersionNumber = "1.1.0" - - private let fileIdentifier = "Created by CommitPrefix \(Self.cpVersionNumber)" + private let fileIdentifier = "Created by CommitPrefix \(CPInfo.version)" private let hooksDirectory: Folder diff --git a/Sources/CommitPrefix/Constants.swift b/Sources/CommitPrefix/Constants.swift index 3dd5462..856c13a 100644 --- a/Sources/CommitPrefix/Constants.swift +++ b/Sources/CommitPrefix/Constants.swift @@ -26,6 +26,12 @@ import Foundation +public struct CPInfo { + + public static let version = "1.3.0" + +} + public struct FileName { public static let commitPrefix = "CommitPrefix.JSON" From b7b609d56c372c444ef5e6adc3279ac91a8e51da Mon Sep 17 00:00:00 2001 From: Stephen Martinez Date: Sat, 14 Dec 2019 16:33:03 -0800 Subject: [PATCH 4/4] [CPFeature-005][NewArgument] Added the new version arg and updated the command switch --- Sources/CommitPrefix/CLIArguments.swift | 19 ++++++++++++++++++- Sources/CommitPrefix/main.swift | 12 ++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/Sources/CommitPrefix/CLIArguments.swift b/Sources/CommitPrefix/CLIArguments.swift index e93a919..0af2b64 100644 --- a/Sources/CommitPrefix/CLIArguments.swift +++ b/Sources/CommitPrefix/CLIArguments.swift @@ -30,6 +30,7 @@ import SPMUtility public struct CLIArguments { public enum UserCommand { + case outputVersion case viewState case outputPrefixes case deletePrefixes @@ -39,6 +40,7 @@ public struct CLIArguments { } private enum ParsedCommand { + case outputVersion case viewState case outputPrefixes case deletePrefixes @@ -50,6 +52,7 @@ public struct CLIArguments { private let parser: ArgumentParser private let rawArgs: [String] + private let outputVersion: OptionArgument private let outputPrefixes: OptionArgument private let deletePrefixes: OptionArgument private let modeNormal: OptionArgument @@ -62,6 +65,7 @@ public struct CLIArguments { let argBuilder = ArgumentBuilder() self.parser = argBuilder.buildParser() + self.outputVersion = argBuilder.buildVersionArgument(parser: parser) self.outputPrefixes = argBuilder.buildOutputArgument(parser: parser) self.deletePrefixes = argBuilder.buildDeleteArgument(parser: parser) self.modeNormal = argBuilder.buildNormalArgument(parser: parser) @@ -76,6 +80,8 @@ public struct CLIArguments { } switch foundCommand { + case .outputVersion: + return .outputVersion case .outputPrefixes: return .outputPrefixes case .deletePrefixes: @@ -111,6 +117,7 @@ public struct CLIArguments { var allCommands = [ParsedCommand]() + parsedArgs.get(outputVersion).map { _ in allCommands.append(.outputVersion) } parsedArgs.get(outputPrefixes).map { _ in allCommands.append(.outputPrefixes) } parsedArgs.get(deletePrefixes).map { _ in allCommands.append(.deletePrefixes) } parsedArgs.get(modeNormal).map { _ in allCommands.append(.modeNormal) } @@ -142,7 +149,7 @@ private struct ArgumentBuilder { let usage: String = """ [,,...] [-o | --output] [-d | --delete] - [-n | -normal] [ -b | --branchParse ] + [-n | -normal] [ -b | --branchParse ] [-v | --version] """ let overview: String = """ @@ -181,6 +188,16 @@ private struct ArgumentBuilder { ArgumentParser(usage: usage, overview: overview) } + func buildVersionArgument(parser: ArgumentParser) -> OptionArgument { + return parser.add( + option: "--version", + shortName: "-v", + kind: Bool.self, + usage: "Outputs the current version information", + completion: nil + ) + } + func buildOutputArgument(parser: ArgumentParser) -> OptionArgument { return parser.add( option: "--output", diff --git a/Sources/CommitPrefix/main.swift b/Sources/CommitPrefix/main.swift index 532af76..186cfec 100644 --- a/Sources/CommitPrefix/main.swift +++ b/Sources/CommitPrefix/main.swift @@ -30,31 +30,39 @@ let cpCommandLineInterface = CLIArguments() do { - let fileHandler = try CPFileHandler() - switch try cpCommandLineInterface.getCommand() { + case .outputVersion: + let version = CPInfo.version + print("commitPrefix version \(version)") + case .viewState: + let fileHandler = try CPFileHandler() let currentState = try fileHandler.viewState() print(currentState) case .outputPrefixes: + let fileHandler = try CPFileHandler() let prefixOutput = try fileHandler.outputPrefixes() print(prefixOutput) case .deletePrefixes: + let fileHandler = try CPFileHandler() let deletionMessage = try fileHandler.deletePrefixes() print(deletionMessage) case .modeNormal: + let fileHandler = try CPFileHandler() let modeSetMessage = try fileHandler.activateNormalMode() print(modeSetMessage) case .modeBranchParse(validator: let rawValidatorValue): + let fileHandler = try CPFileHandler() let modeSetMessage = try fileHandler.activateBranchMode(with: rawValidatorValue) print(modeSetMessage) case .newPrefixes(value: let rawPrefixValue): + let fileHandler = try CPFileHandler() let storedPrefixesMessage = try fileHandler.writeNew(prefixes: rawPrefixValue) print(storedPrefixesMessage)