Sha256: 020399be6a9a03e91af7b15d8e4579a4348572efdab913bf6054c3f2d22a0636

Contents?: true

Size: 1.43 KB

Versions: 2

Compression:

Stored size: 1.43 KB

Contents

require 'yaml'
require 'simple_commander/helpers/io'
require 'byebug'

module SimpleCommander
	class CLI
		include IO_helper
		DEFAULT_PATH = "#{File.dirname(__FILE__)}/config.yml"
		attr_accessor :config_file

		class UndefinedSCPath < StandardError
			def initialize
				msg = <<-END 
					You need to set a path to commander
					use simple_commander init <path> or cd to
					the folder you want and just simple_commander init
				END
				super(msg)
			end
		end
		
		def initialize(path=DEFAULT_PATH)
			@config_file = path
		end

		def init(path='./')
			if path
				local_path = File.expand_path(path)
			else
				local_path = File.expand_path('./')
			end

			yml = { path: local_path }.to_yaml
			File.open(@config_file, 'w+'){|f| f.write(yml)}
		end

		def show_config
			say YAML.load_file(@config_file)
		end

		def new(*args)
			sc_path = YAML.load_file(@config_file)[:path]
			raise UndefinedSCPath if !sc_path
			s_path = "#{sc_path}/#{args[0]}"
			raise StandardError "program #{args[0]} already exists!"  if File.directory?(s_path)
			@program_name = args[0]
			mkdir s_path 
			mkdir "#{s_path}/bin"
			mkdir "#{s_path}/spec"
			mkdir "#{s_path}/lib"
			mkdir "#{s_path}/lib/#{@program_name}"
			template './templates/lib.erb',
				"#{s_path}/lib/#{@program_name}.rb"
			template './templates/version.erb',
				"#{s_path}/lib/#{@program_name}/version.rb"
			template './templates/bin.erb',
				"#{s_path}/bin/#{@program_name}"
		end
	end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
simple_commander-0.3.1 lib/simple_commander/cli.rb
simple_commander-0.3.0 lib/simple_commander/cli.rb