Class: Jeny::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/jeny/command.rb,
lib/jeny/command/support.rb,
lib/jeny/command/generate.rb,
lib/jeny/command/snippets.rb

Defined Under Namespace

Modules: Support Classes: Generate, Snippets

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCommand

Returns a new instance of Command.



5
6
7
8
# File 'lib/jeny/command.rb', line 5

def initialize
  @config = nil
  @jeny_data = {}
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



10
11
12
# File 'lib/jeny/command.rb', line 10

def config
  @config
end

#jeny_dataObject (readonly)

Returns the value of attribute jeny_data.



9
10
11
# File 'lib/jeny/command.rb', line 9

def jeny_data
  @jeny_data
end

Class Method Details

.call(argv) ⇒ Object



12
13
14
15
16
17
# File 'lib/jeny/command.rb', line 12

def self.call(argv)
  new.call(argv)
rescue Error => ex
  puts ex.message
  exit(1)
end

Instance Method Details

#call(argv) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/jeny/command.rb', line 19

def call(argv)
  args = parse_argv!(argv, load_config!)
  case command = args.first
  when "g", "generate"
    _, from, to = args
    from, to = Path(from), Path(to)
    raise Error, "No such template `#{from}`" unless from.directory?
    to.mkdir_p
    Generate.new(@config, jeny_data, from, to).call
  when "s", "snippets"
    _, asset, *source = args
    raise Error, "Asset must be specified" if asset.nil? or Path(asset).exist?
    source = [Path.pwd] if source.empty?
    from = source.map{|t| Path(t) }
    Snippets.new(@config, jeny_data, asset, from).call
  else
    raise Error, "Unknown command `#{command}`"
  end
end

#parse_argv!(argv, config = Configuration.new) ⇒ Object



39
40
41
42
# File 'lib/jeny/command.rb', line 39

def parse_argv!(argv, config = Configuration.new)
  @config = config
  option_parser(config).parse!(argv)
end