Class: Sinatras::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/sinatras/command.rb,
lib/sinatras/command/options.rb

Overview

コマンドライン処理を行うクラス

Defined Under Namespace

Modules: Options

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Command

Returns a new instance of Command


22
23
24
# File 'lib/sinatras/command.rb', line 22

def initialize(argv)
  @argv = argv
end

Class Method Details

.run(argv) ⇒ Object


18
19
20
# File 'lib/sinatras/command.rb', line 18

def self.run(argv)
  new(argv).execute
end

Instance Method Details

#executeObject


8
9
10
11
12
13
14
15
16
# File 'lib/sinatras/command.rb', line 8

def execute
  options = Options.parse!(@argv)
  sub_command = options.delete(:command)

  tasks = case sub_command
          when 'new'
            new(options)
          end
end

#new(options) ⇒ Object


130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/sinatras/command.rb', line 130

def new(options)
  appname = options[:appname]
  if options[:appname] !~ /^[a-z_]+[a-zA-Z0-9_]*$/
    puts 'appname format is (a-z or _ ) + (alphabet,0-9, and _)'
    exit
  end
  if (File.directory?(appname))
    puts 'appname same name of the directory exist'
    exit
  end

  make_dir(appname)
  make_file(appname)
  change_permission(appname)
  do_gitcommand(appname)
  1
end