feat: Renames some options, adds a require-configuration option that fails if configuration is not found.
All checks were successful
CI / Ubuntu (push) Successful in 2m19s

This commit is contained in:
2024-12-27 16:42:48 -05:00
parent 4420bd428a
commit 20f430fb8f
16 changed files with 133 additions and 154 deletions

View File

@@ -18,7 +18,7 @@ struct BumpCommand: CommandRepresentable {
),
makeExample(
label: "Dry run, just show what the bumped version would be.",
example: "--minor --dry-run"
example: "--minor --print"
)
])
)

View File

@@ -149,8 +149,6 @@ extension ConfigCommand {
}
}
// TODO: Add verbose.
// TODO: Need to be able to generate a branch style config file.
@dynamicMemberLookup
struct ConfigCommandOptions: ParsableArguments {
@@ -210,12 +208,6 @@ private extension ConfigCommand.ConfigCommandOptions {
case .swift:
customDump(configuration)
}
// guard printJson else {
// customDump(configuration)
// return
// }
// try handlePrintJson(configuration)
}
}

View File

@@ -10,7 +10,9 @@ by the module that a `Version.swift` file resides in. It also declares the strat
new versions.
The command-line tool comes with a command to generate the configuration file for you, this should
be ran from the root of your project.
be ran from the root of your project or by specifying the path to write the configuration file to
using the `-f | --configuration-file` option. The below examples assume that you're running in the
root project directory.
```bash
bump-version config generate --target-module my-tool

View File

@@ -39,10 +39,18 @@ are ignored if your configuration or options specify to use a `branch` strategy.
bump-version bump --minor
```
If you want to use the default configuration without generating your own project configuration, then
you can specify the path or module to the bump command. The default configuration will use the
`gitTag` strategy without any pre-release strategy.
```bash
bump-version bump --minor --target-module my-tool
```
Show the output, but don't update the version file.
```bash
bump-version bump --major --dry-run
bump-version bump --major --print
```
### Generate Command
@@ -66,11 +74,10 @@ Generates a configuration file based on the passed in options.
The following options are used to declare strategy used for deriving the version.
| Long | Description |
| -------- | ------------------------------------------------------- |
| --branch | Use the branch strategy |
| --semvar | Use the semvar strategy (default) |
| --print | Print the output to stdout instead of generating a file |
| Long | Description |
| -------- | --------------------------------- |
| --branch | Use the branch strategy |
| --semvar | Use the semvar strategy (default) |
##### Generate Configuration Example

View File

@@ -9,13 +9,13 @@ of their usage.
### General Options
| Short | Long | Argument | Description |
| ----- | --------------- | -------- | -------------------------------------------------------------------- |
| N/A | --dry-run | N/A | Perform the command, but don't write any output files |
| N/A | --git-directory | <path> | The path to the root of your project, defaults to current directory |
| -h | --help | N/A | Show help for a command |
| -v | --verbose | N/A | Increase logging level, can be passed multiple times (example: -vvv) |
| N/A | --version | N/A | Show the version of the command line tool |
| Short | Long | Argument | Description |
| ----- | ------------------- | -------- | -------------------------------------------------------------------- |
| N/A | --print | N/A | Perform the command, but don't write any output files |
| N/A | --project-directory | <path> | The path to the root of your project, defaults to current directory |
| -h | --help | N/A | Show help for a command |
| -v | --verbose | N/A | Increase logging level, can be passed multiple times (example: -vvv) |
| N/A | --version | N/A | Show the version of the command line tool |
### Configuration Options
@@ -30,6 +30,7 @@ of their usage.
| N/A | --require-existing-semvar | N/A | Fail if an existing semvar is not found in the version file. |
| -c | --custom-command | <arguments> | Use a custom command strategy for the version (any options need to proceed a '--') |
| N/A | --commit-sha/--no-commit-sha | N/A | Use the commit sha with branch version or pre-release strategy |
| N/A | --require-configuration | N/A | Fail if a configuration file is not found |
#### Pre-Release Options

View File

@@ -13,13 +13,13 @@ struct GlobalOptions: ParsableArguments {
var configOptions: ConfigurationOptions
@Option(
name: .customLong("git-directory"),
help: "The git directory for the version (default: current directory)"
name: .customLong("project-directory"),
help: "The project directory. (default: current directory)"
)
var gitDirectory: String?
var projectDirectory: String?
@Flag(
name: .customLong("dry-run"),
name: .customLong("print"),
help: "Print's what would be written to a target version file."
)
var dryRun: Bool = false
@@ -41,6 +41,7 @@ struct GlobalOptions: ParsableArguments {
}
struct ConfigurationOptions: ParsableArguments {
@Option(
name: [.customShort("f"), .long],
help: "Specify the path to a configuration file. (default: .bump-version.json)",
@@ -61,6 +62,14 @@ struct ConfigurationOptions: ParsableArguments {
)
var commitSha: Bool = true
@Flag(
name: .long,
help: """
Require a configuration file, otherwise fail.
"""
)
var requireConfiguration: Bool = false
}
struct TargetOptions: ParsableArguments {
@@ -126,7 +135,6 @@ struct PreReleaseOptions: ParsableArguments {
}
// TODO: Add custom command strategy.
struct SemVarOptions: ParsableArguments {
@Flag(

View File

@@ -64,7 +64,7 @@ extension GlobalOptions {
command: command,
dryRun: dryRun,
extraOptions: extraOptions,
gitDirectory: gitDirectory,
gitDirectory: projectDirectory,
verbose: verbose
)
}
@@ -129,7 +129,6 @@ extension SemVarOptions {
) throws -> Configuration.SemVar {
@Dependency(\.logger) var logger
// TODO: Update when / if there's an update config command.
if customCommand && preRelease.customPreRelease {
logger.warning("""
Custom pre-release can not be used at same time as custom command.
@@ -167,6 +166,15 @@ extension ConfigurationOptions {
)
}
private func configurationToMerge(extraOptions: [String]) throws -> Configuration {
try .init(
target: target(),
strategy: semvarOptions.gitTag
? .semvar(semvarOptions(extraOptions: extraOptions))
: .branch(includeCommitSha: commitSha)
)
}
func shared(
command: String,
dryRun: Bool = true,
@@ -177,12 +185,11 @@ extension ConfigurationOptions {
try .init(
allowPreReleaseTag: !semvarOptions.preRelease.disablePreRelease,
dryRun: dryRun,
gitDirectory: gitDirectory,
projectDirectory: gitDirectory,
loggingOptions: .init(command: command, verbose: verbose),
target: target(),
branch: semvarOptions.gitTag ? nil : .init(includeCommitSha: commitSha),
semvar: semvarOptions(extraOptions: extraOptions),
configurationFile: configurationFile
configurationToMerge: configurationToMerge(extraOptions: extraOptions),
configurationFile: configurationFile,
requireConfigurationFile: requireConfiguration
)
}
}