Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 22 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<UserName>/Library/Developer/Xcode/DerivedData/commitPrefix-<GeneratedString>/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 --
Expand Down
19 changes: 18 additions & 1 deletion Sources/CommitPrefix/CLIArguments.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import SPMUtility
public struct CLIArguments {

public enum UserCommand {
case outputVersion
case viewState
case outputPrefixes
case deletePrefixes
Expand All @@ -39,6 +40,7 @@ public struct CLIArguments {
}

private enum ParsedCommand {
case outputVersion
case viewState
case outputPrefixes
case deletePrefixes
Expand All @@ -50,6 +52,7 @@ public struct CLIArguments {
private let parser: ArgumentParser
private let rawArgs: [String]

private let outputVersion: OptionArgument<Bool>
private let outputPrefixes: OptionArgument<Bool>
private let deletePrefixes: OptionArgument<Bool>
private let modeNormal: OptionArgument<Bool>
Expand All @@ -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)
Expand All @@ -76,6 +80,8 @@ public struct CLIArguments {
}

switch foundCommand {
case .outputVersion:
return .outputVersion
case .outputPrefixes:
return .outputPrefixes
case .deletePrefixes:
Expand Down Expand Up @@ -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) }
Expand Down Expand Up @@ -142,7 +149,7 @@ private struct ArgumentBuilder {

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

let overview: String = """
Expand Down Expand Up @@ -181,6 +188,16 @@ private struct ArgumentBuilder {
ArgumentParser(usage: usage, overview: overview)
}

func buildVersionArgument(parser: ArgumentParser) -> OptionArgument<Bool> {
return parser.add(
option: "--version",
shortName: "-v",
kind: Bool.self,
usage: "Outputs the current version information",
completion: nil
)
}

func buildOutputArgument(parser: ArgumentParser) -> OptionArgument<Bool> {
return parser.add(
option: "--output",
Expand Down
1 change: 1 addition & 0 deletions Sources/CommitPrefix/CPError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ enum CPError: Error {

}

/// An Error Type that should terminate the program if detected
enum CPTermination: Error {

case overwriteCancelled
Expand Down
4 changes: 1 addition & 3 deletions Sources/CommitPrefix/CommitMessageHook.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions Sources/CommitPrefix/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 10 additions & 2 deletions Sources/CommitPrefix/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down