lib/gemsmith/cli/actions/publish.rb in gemsmith-19.8.0 vs lib/gemsmith/cli/actions/publish.rb in gemsmith-20.0.0
- old
+ new
@@ -1,36 +1,47 @@
# frozen_string_literal: true
require "dry/monads"
+require "pathname"
+require "sod"
require "spek"
module Gemsmith
module CLI
module Actions
# Handles the publish action.
- class Publish
+ class Publish < Sod::Action
include Gemsmith::Import[:logger]
include Dry::Monads[:result]
+ description "Publish gem to remote gem server."
+
+ ancillary "Optionally computes gem package based on current directory."
+
+ on %w[-p --publish], argument: "[GEM]"
+
+ default { Pathname.pwd.basename }
+
def initialize(publisher: Tools::Publisher.new, loader: Spek::Loader, **)
super(**)
@publisher = publisher
@loader = loader
end
- def call configuration
- case publisher.call loader.call("#{configuration.project_name}.gemspec")
+ # :reek:ControlParameter
+ def call name = nil
+ case publisher.call loader.call("#{name || default}.gemspec")
in Success(spec) then logger.info { "Published: #{spec.package_name}." }
- in Failure(message) then error { message }
- else error { "Unable to handle publish action." }
+ in Failure(message) then log_error { message }
+ else log_error { "Unable to handle publish action." }
end
end
private
attr_reader :publisher, :loader
- def error(&) = logger.error(&)
+ def log_error(&) = logger.error(&)
end
end
end
end