Skip to content

Commit b1969df

Browse files
authored
Merge pull request #3 from enuance/CPFeature-005-AddNewVersionArg
CPFeature-005 Add New Version Argument.
2 parents d3f874f + b7b609d commit b1969df

File tree

6 files changed

+58
-24
lines changed

6 files changed

+58
-24
lines changed

README.md

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,45 +20,49 @@ The actions that can be done are:
2020
* View the current mode and stored prefixes
2121

2222
___
23-
### -- Installation --
23+
### -- Requirements --
2424

25-
1. Clone the repo
25+
This package uses `swift-tools-version:5.1` as a minimum requirement to build and install.
2626

27+
Check to see that you have Swift 5.1 or greater to meet the requirements
2728
```zsh
28-
% git clone https://github.com/enuance/commitPrefix.git
29+
% swift --version
2930
```
3031

31-
2. Open the Package
32+
Supported OS:
33+
- macOS Catalina v10.15.1 or greater
34+
35+
___
36+
### -- Installation --
37+
38+
1. Clone the repo and move to the root of the directory
3239

3340
```zsh
41+
% git clone https://github.com/enuance/commitPrefix.git
3442
% cd commitPrefix
35-
% open Package.swift
3643
```
3744

38-
3. Build the executable by pressing **⌘B** or select it from the menu **Product -> Build**
39-
40-
4. Locate the executable by running this in the terminal
45+
2. *Optional* Run the installer
4146

4247
```zsh
43-
% find ~/Library/Developer/Xcode/DerivedData -name "commitPrefix"
48+
% ./Installer
4449
```
4550

46-
This command will display all locations where files have the name “commitPrefix”
47-
It should be the one contained in `/Users/<UserName>/Library/Developer/Xcode/DerivedData/commitPrefix-<GeneratedString>/Build/Products/Release/commitPrefix`
48-
49-
Make sure not to select ones that have `commitPrefix.dSYM` in it's path
51+
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:
5052

51-
5. Open a window at the location by using Finder and selecting **Go -> Go to folder...** enter in the path and select **Go**
53+
2. Build the executable
5254

53-
You can also use the terminal **open** command but you'd have to remove the executable `/commitPrefix` from the end of the path
55+
```zsh
56+
% swift build -c release
57+
```
5458

55-
6. Open your local executables folder by entering:
59+
3. Install it into the local bin folder
5660

5761
```zsh
58-
% open /usr/local/bin
62+
% mv .build/release/commitPrefix /usr/local/bin
5963
```
6064

61-
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.
65+
On your next Terminal session you should be able to see auto-completion and use commitPrefix.
6266

6367
___
6468
### -- Usage --

Sources/CommitPrefix/CLIArguments.swift

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import SPMUtility
3030
public struct CLIArguments {
3131

3232
public enum UserCommand {
33+
case outputVersion
3334
case viewState
3435
case outputPrefixes
3536
case deletePrefixes
@@ -39,6 +40,7 @@ public struct CLIArguments {
3940
}
4041

4142
private enum ParsedCommand {
43+
case outputVersion
4244
case viewState
4345
case outputPrefixes
4446
case deletePrefixes
@@ -50,6 +52,7 @@ public struct CLIArguments {
5052
private let parser: ArgumentParser
5153
private let rawArgs: [String]
5254

55+
private let outputVersion: OptionArgument<Bool>
5356
private let outputPrefixes: OptionArgument<Bool>
5457
private let deletePrefixes: OptionArgument<Bool>
5558
private let modeNormal: OptionArgument<Bool>
@@ -62,6 +65,7 @@ public struct CLIArguments {
6265
let argBuilder = ArgumentBuilder()
6366
self.parser = argBuilder.buildParser()
6467

68+
self.outputVersion = argBuilder.buildVersionArgument(parser: parser)
6569
self.outputPrefixes = argBuilder.buildOutputArgument(parser: parser)
6670
self.deletePrefixes = argBuilder.buildDeleteArgument(parser: parser)
6771
self.modeNormal = argBuilder.buildNormalArgument(parser: parser)
@@ -76,6 +80,8 @@ public struct CLIArguments {
7680
}
7781

7882
switch foundCommand {
83+
case .outputVersion:
84+
return .outputVersion
7985
case .outputPrefixes:
8086
return .outputPrefixes
8187
case .deletePrefixes:
@@ -111,6 +117,7 @@ public struct CLIArguments {
111117

112118
var allCommands = [ParsedCommand]()
113119

120+
parsedArgs.get(outputVersion).map { _ in allCommands.append(.outputVersion) }
114121
parsedArgs.get(outputPrefixes).map { _ in allCommands.append(.outputPrefixes) }
115122
parsedArgs.get(deletePrefixes).map { _ in allCommands.append(.deletePrefixes) }
116123
parsedArgs.get(modeNormal).map { _ in allCommands.append(.modeNormal) }
@@ -142,7 +149,7 @@ private struct ArgumentBuilder {
142149

143150
let usage: String = """
144151
[<PrefixValue1>,<PrefixValue2>,<PrefixValue3>...] [-o | --output] [-d | --delete]
145-
[-n | -normal] [ -b | --branchParse <ValidatorValue> ]
152+
[-n | -normal] [ -b | --branchParse <ValidatorValue> ] [-v | --version]
146153
"""
147154

148155
let overview: String = """
@@ -181,6 +188,16 @@ private struct ArgumentBuilder {
181188
ArgumentParser(usage: usage, overview: overview)
182189
}
183190

191+
func buildVersionArgument(parser: ArgumentParser) -> OptionArgument<Bool> {
192+
return parser.add(
193+
option: "--version",
194+
shortName: "-v",
195+
kind: Bool.self,
196+
usage: "Outputs the current version information",
197+
completion: nil
198+
)
199+
}
200+
184201
func buildOutputArgument(parser: ArgumentParser) -> OptionArgument<Bool> {
185202
return parser.add(
186203
option: "--output",

Sources/CommitPrefix/CPError.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ enum CPError: Error {
6565

6666
}
6767

68+
/// An Error Type that should terminate the program if detected
6869
enum CPTermination: Error {
6970

7071
case overwriteCancelled

Sources/CommitPrefix/CommitMessageHook.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ import Foundation
2929

3030
public struct CommitMessageHook {
3131

32-
private static let cpVersionNumber = "1.1.0"
33-
34-
private let fileIdentifier = "Created by CommitPrefix \(Self.cpVersionNumber)"
32+
private let fileIdentifier = "Created by CommitPrefix \(CPInfo.version)"
3533

3634
private let hooksDirectory: Folder
3735

Sources/CommitPrefix/Constants.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@
2626

2727
import Foundation
2828

29+
public struct CPInfo {
30+
31+
public static let version = "1.3.0"
32+
33+
}
34+
2935
public struct FileName {
3036

3137
public static let commitPrefix = "CommitPrefix.JSON"

Sources/CommitPrefix/main.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,31 +30,39 @@ let cpCommandLineInterface = CLIArguments()
3030

3131
do {
3232

33-
let fileHandler = try CPFileHandler()
34-
3533
switch try cpCommandLineInterface.getCommand() {
3634

35+
case .outputVersion:
36+
let version = CPInfo.version
37+
print("commitPrefix version \(version)")
38+
3739
case .viewState:
40+
let fileHandler = try CPFileHandler()
3841
let currentState = try fileHandler.viewState()
3942
print(currentState)
4043

4144
case .outputPrefixes:
45+
let fileHandler = try CPFileHandler()
4246
let prefixOutput = try fileHandler.outputPrefixes()
4347
print(prefixOutput)
4448

4549
case .deletePrefixes:
50+
let fileHandler = try CPFileHandler()
4651
let deletionMessage = try fileHandler.deletePrefixes()
4752
print(deletionMessage)
4853

4954
case .modeNormal:
55+
let fileHandler = try CPFileHandler()
5056
let modeSetMessage = try fileHandler.activateNormalMode()
5157
print(modeSetMessage)
5258

5359
case .modeBranchParse(validator: let rawValidatorValue):
60+
let fileHandler = try CPFileHandler()
5461
let modeSetMessage = try fileHandler.activateBranchMode(with: rawValidatorValue)
5562
print(modeSetMessage)
5663

5764
case .newPrefixes(value: let rawPrefixValue):
65+
let fileHandler = try CPFileHandler()
5866
let storedPrefixesMessage = try fileHandler.writeNew(prefixes: rawPrefixValue)
5967
print(storedPrefixesMessage)
6068

0 commit comments

Comments
 (0)