Sha256: 17061ee383908d245dcfc76408e099b977ff1b25d2fc70fee9fc3fed41823f45

Contents?: true

Size: 1.21 KB

Versions: 25

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

require "clamp"

module Makit
  module Cli
    # Define the 'new' subcommand
    class NewCommand < Clamp::Command
      AVAILABLE_TYPES = %w[gem crate nuget].freeze
      option "--list", :flag, "List available types"
      option ["-o", "--output"], "OUTPUT_DIR", "Specify output directory", default: "."
      option ["-t", "--type"], "TYPE", "Type of the new entity", default: "gem"
      parameter "TYPE", "Type of the new entity", attribute_name: :type, required: false
      parameter "NAME", "Name of the new entity", attribute_name: :name, required: false
      parameter "DIRECTORY", "The output directory", attribute_name: :name, required: false

      def execute
        if list?
          puts "Available types:"
          AVAILABLE_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 AVAILABLE_TYPES.include?(type)
            puts "Error: '#{type}' is not a valid type. Use --list to see available types."
            exit(1)
          end

          puts "Creating a new #{type} named #{name}."
        end
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
makit-0.0.27 lib/makit/cli/new.rb
makit-0.0.5 lib/makit/cli/new.rb
makit-0.0.4 lib/makit/cli/new.rb
makit-0.0.3 lib/makit/cli/new.rb
makit-0.0.2 lib/makit/cli/new.rb