lib/commands/version.rb in gfsm-0.3.2 vs lib/commands/version.rb in gfsm-0.4.0
- old
+ new
@@ -3,79 +3,50 @@
module GFSM
module Commands
class Version < BaseCommand
def self.help
+ cli_info = GFSM::Tools::VersionBumperSettings.cli_info
+
<<~HELP
- Usage: gfsm version [help] [bump [--force] [--prerelease] [--prerelease-name <prerelease_name>] [--configuration <configuration_file_path>] [--path <repository_path]]
+ Usage:
+ gfsm version [help|bump|current] #{cli_info[:usage]}
- Arguments:
- help # Prints this help
- bump # Bump the current version based on the commits
- # changelog trailer and the configuration file
- --force # When there are no commits with a changelog trailer
- # the version won't get bumped. Use this flag to force
- # the version bump (will increase the patch version)
- --prerelease # Use this switch to also include a prerelease in the version.
- # By default will add 'pre' and increment it like 'pre.1',
- # 'pre.2' and so on
- --prerelease-name <name> # Name of the prerelease that will get added when the
- # switch is enabled
- --configuration <path> # Path to the configuration YAML file
- --path <path> # Path to the repository. By default will use the current directory
+ Commands:
+ help # Prints this help
+ bump # Bump the current version based on the commits changelog trailer and the configuration file
+ current # Print the current version, without bumping it
+
+ Options: \n#{cli_info[:options]}
+
+ Environment variables: \n#{cli_info[:environment_variables]}
HELP
end
def run(args = [])
- if args.empty? || (args.length == 2 && args[0] != "bump")
- repository_path = get_repository_path(args)
-
- GFSM::Output.puts GFSM::Tools::CurrentVersionLoader.load_current_version(repository_path)
- return true
- end
-
case args.shift
when 'bump'
- force = args.include?("--force")
- prerelease = args.include?("--prerelease")
- prerelease_name = get_prerelease_name(args)
- repository_path = get_repository_path(args)
- configuration_file_path = get_configuration_file_path(args)
+ settings = GFSM::Tools::VersionBumperSettings.new(args)
+ version_bumper = GFSM::Tools::VersionBumper.new(settings)
+ version = version_bumper.execute
- version_bumper = GFSM::Tools::VersionBumper.new()
- version = version_bumper.compute_version!(force, prerelease, prerelease_name, repository_path, configuration_file_path)
+ GFSM::Output.puts(version)
+ when 'current'
+ settings = GFSM::Tools::VersionBumperSettings.new(args)
+ version = GFSM::Tools::CurrentVersionLoader.load_current_version(settings.repository)
+ if settings.prerelease
+ version.add_prerelease_suffix!(settings.prerelease_name)
+ end
+
GFSM::Output.puts(version)
when 'help'
GFSM::Output.puts(GFSM::Commands::Version.help)
else
GFSM::Output.warn(GFSM::Commands::Version.help)
end
true
- end
-
- private
-
- def extract_switch_value(args, switch, default_value)
- switch_index = args.find_index(switch)
-
- return default_value unless switch_index &&
- (switch_index + 1) < args.length
-
- args[switch_index + 1]
- end
-
- def get_configuration_file_path(args)
- extract_switch_value(args, "--configuration", "./gfsmrc.yml")
- end
-
- def get_prerelease_name(args)
- extract_switch_value(args, "--prerelease-name", "pre")
- end
-
- def get_repository_path(args)
- extract_switch_value(args, "--path", ".")
end
end
end
end
\ No newline at end of file