Class: Packager::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/packager/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Make sure to exit(1) on failure. This isn’t covered in the specs. :nocov:

Returns:

  • (Boolean)


8
9
10
# File 'lib/packager/cli.rb', line 8

def self.exit_on_failure?
  true
end

Instance Method Details

#__print_versionObject



16
17
18
# File 'lib/packager/cli.rb', line 16

def __print_version
  puts Packager::VERSION
end

#execute(*args) ⇒ Object



24
25
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
51
52
53
54
55
56
57
# File 'lib/packager/cli.rb', line 24

def execute(*args)
  if args.empty?
    raise Thor::Error, "No filenames provided for execute"
  end

  (options['var'] || {}).each do |name, value|
    if Packager::DSL.reserved_words.include? name
      raise Thor::Error, "'#{name}' is a reserved word"
    end
    Packager::DSL.add_helper(name.to_sym) { value }
  end

  args.each do |filename|
    unless File.exists? filename
      raise Thor::Error, "'#{filename}' cannot be found"
    end

    begin
      items = Packager::DSL.parse_dsl(IO.read(filename))
    rescue Exception => e
      raise Thor::Error, "'#{filename}' has the following errors:\n#{e}"
    end

    if items.empty?
      raise Thor::Error, "'#{filename}' produces nothing"
    end

    packages = Packager::Executor.new(
      dryrun: options['dryrun'],
    ).execute_on(items)

    puts "'#{filename}' executed #{packages.join(', ')}"
  end
end

#validate(*args) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/packager/cli.rb', line 60

def validate(*args)
  if args.empty?
    raise Thor::Error, "No filenames provided for validate"
  end

  args.each do |filename|
    unless File.exists? filename
      raise Thor::Error, "'#{filename}' cannot be found"
    end

    begin
      items = Packager::DSL.parse_dsl(IO.read(filename))
    rescue Exception => e
      raise Thor::Error, "'#{filename}' has the following errors:\n#{e}"
    end

    if items.empty?
      raise Thor::Error, "'#{filename}' produces nothing"
    end

    puts "'#{filename}' parses cleanly"
  end
end