lib/makit/cli/setup.rb in makit-0.0.53 vs lib/makit/cli/setup.rb in makit-0.0.54

- old
+ new

@@ -1,71 +1,71 @@ -# frozen_string_literal: true - -require "clamp" - -module Makit - module Cli - # Define the 'new' subcommand - class SetupCommand < Clamp::Command - PACKAGE_TYPES = %w[gem crate nuget].freeze - option "--list", :flag, "List available package types" - option ["-t", "--type"], "TYPE", "The package type", default: "gem" - option ["-o", "--output"], "OUTPUT", "The output directory", default: "." - parameter "TYPE", "Type of the package", attribute_name: :type, required: false - parameter "NAME", "Name of the package", attribute_name: :name, required: false - - def execute - if list? - puts "Available package types:" - PACKAGE_TYPES.each { |t| puts " - #{t}" } - else - if type.nil? || name.nil? - puts "Error: TYPE and NAME are required unless using --list" - exit(1) - end - - unless PACKAGE_TYPES.include?(type) - puts "Error: '#{type}' is not a valid type. Use --list to see available types." - exit(1) - end - - if !Makit::IS_GIT_REPO - Makit::LOGGER.error("#{Dir.pwd} does not appear to be a git repository.") - exit(1) - end - if Makit::IS_READ_ONLY - Makit::LOGGER.error("The git repository is in a read-only state.") - exit(1) - end - - # if a Rakefile already exists, then the project has already been setup - if File.exist?("Rakefile") - Makit::LOGGER.error("Rakefile detected, The project has already been setup.") - exit(1) - end - - # verify the root directory has a .gitignore file - if !File.exist?(".gitignore") - Makit::LOGGER.info("added .gitignore file") - File.open(".gitignore", "w") do |file| - file.puts Makit::Content::GITIGNORE - end - end - - # verify the root directory has a Rakefile - - if (type == "gem") - if !File.exist?("Gemfile") - Makit::RUNNER.run("bundle gem . --coc --mit --exe --no-git --ci=gitlab_ci --test=minitest --changelog --linter=rubocop") - - # overwrite the Rakefile with the one from the gem template - File.open("Rakefile", "w") do |file| - file.puts Makit::Content::GEM_RAKEFILE.gsub("GEM_NAME", name) - end - end - end - # Makit::LOGGER.info("bundle gem . --coc --mit --exe --no-git --ci=gitlab_ci --test=minitest --changelog --linter=rubocop --skip=Rakefile,README.md") - end - end - end - end -end +# frozen_string_literal: true + +require "clamp" + +module Makit + module Cli + # Define the 'new' subcommand + class SetupCommand < Clamp::Command + PACKAGE_TYPES = %w[gem crate nuget].freeze + option "--list", :flag, "List available package types" + option ["-t", "--type"], "TYPE", "The package type", default: "gem" + option ["-o", "--output"], "OUTPUT", "The output directory", default: "." + parameter "TYPE", "Type of the package", attribute_name: :type, required: false + parameter "NAME", "Name of the package", attribute_name: :name, required: false + + def execute + if list? + puts "Available package types:" + PACKAGE_TYPES.each { |t| puts " - #{t}" } + else + if type.nil? || name.nil? + puts "Error: TYPE and NAME are required unless using --list" + exit(1) + end + + unless PACKAGE_TYPES.include?(type) + puts "Error: '#{type}' is not a valid type. Use --list to see available types." + exit(1) + end + + if !Makit::IS_GIT_REPO + Makit::LOGGER.error("#{Dir.pwd} does not appear to be a git repository.") + exit(1) + end + if Makit::IS_READ_ONLY + Makit::LOGGER.error("The git repository is in a read-only state.") + exit(1) + end + + # if a Rakefile already exists, then the project has already been setup + if File.exist?("Rakefile") + Makit::LOGGER.error("Rakefile detected, The project has already been setup.") + exit(1) + end + + # verify the root directory has a .gitignore file + if !File.exist?(".gitignore") + Makit::LOGGER.info("added .gitignore file") + File.open(".gitignore", "w") do |file| + file.puts Makit::Content::GITIGNORE + end + end + + # verify the root directory has a Rakefile + + if (type == "gem") + if !File.exist?("Gemfile") + Makit::RUNNER.run("bundle gem . --coc --mit --exe --no-git --ci=gitlab_ci --test=minitest --changelog --linter=rubocop") + + # overwrite the Rakefile with the one from the gem template + File.open("Rakefile", "w") do |file| + file.puts Makit::Content::GEM_RAKEFILE.gsub("GEM_NAME", name) + end + end + end + # Makit::LOGGER.info("bundle gem . --coc --mit --exe --no-git --ci=gitlab_ci --test=minitest --changelog --linter=rubocop --skip=Rakefile,README.md") + end + end + end + end +end