Class: SRS::CLI::Init
- Inherits:
-
Object
- Object
- SRS::CLI::Init
- Defined in:
- lib/srs/cli/init.rb
Instance Method Summary collapse
- #help ⇒ Object
-
#initialize ⇒ Init
constructor
A new instance of Init.
- #run!(arguments) ⇒ Object
Constructor Details
#initialize ⇒ Init
Returns a new instance of Init.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/srs/cli/init.rb', line 7 def initialize @options = {} @opts = OptionParser.new do |o| o. = <<-EOF.gsub /^\s+/, "" srs init [options] [dirname] Initialises a workspace in directory [dirname]. A `.srs/` folder will be created containing the default configuration files. A skeleton directory structure may also be created (this is undecided as yet). If no [dirname] is passed, uses the current directory. EOF o.on('-f', '--force', 'Initialise workspace even if the directory is not empty') do @options[:force] = true end end end |
Instance Method Details
#help ⇒ Object
52 53 54 |
# File 'lib/srs/cli/init.rb', line 52 def help() puts @opts end |
#run!(arguments) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/srs/cli/init.rb', line 26 def run!(arguments) begin @opts.parse!(arguments) @options[:dir_name] = arguments.shift rescue OptionParser::InvalidOption => e @options[:invalid_argument] = e. end if @options[:dir_name] == nil then @options[:dir_name] = "./" end begin SRS::Workspace.create(@options[:dir_name], @options[:force]) rescue SRS::Workspace::AlreadyInitialisedError => e puts "SRS is already initialised in #{@options[:dir_name]}." return 2 rescue SRS::Workspace::FolderNotEmptyError => e puts "The current folder is not empty!" puts "Run 'srs init --force' to initialise in this folder anyway." return 1 end 0 end |