Class: Ballantine::CLI

Inherits:
Thor
  • Object
show all
Includes:
Printable
Defined in:
lib/ballantine/cli.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Printable

#cols, #puts_r, #rjust_size

Instance Attribute Details

#repoObject (readonly)

Returns the value of attribute repo.



7
8
9
# File 'lib/ballantine/cli.rb', line 7

def repo
  @repo
end

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


10
# File 'lib/ballantine/cli.rb', line 10

def exit_on_failure?; exit(1) end

Instance Method Details

#config(key = nil, value = nil) ⇒ Object

Raises:



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ballantine/cli.rb', line 27

def config(key = nil, value = nil)
  conf.verbose = options["verbose"]
  puts "$ ballantine config #{key} #{value}" if conf.verbose

  # check environment value
  if Config::AVAILABLE_ENVIRONMENTS.map { |key| !options[key] }.reduce(:&)
    raise NotAllowed, "Set environment value (#{Config::AVAILABLE_ENVIRONMENTS.map { |key| "`--#{key}'" }.join(", ")})"
  elsif Config::AVAILABLE_ENVIRONMENTS.map { |key| !!options[key] }.reduce(:&)
    raise NotAllowed, "Environment value must be unique."
  end

  env = Config::AVAILABLE_ENVIRONMENTS.find { |key| options[key] }
  raise AssertionFailed, "Environment value must exist: #{env}" if env.nil?

  conf.env = env
  value ? conf.set_data(key, value) : conf.print_data(key)
end

#diff(target, source = %x(git rev-parse --abbrev-ref HEAD).chomp) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/ballantine/cli.rb', line 48

def diff(target, source = %x(git rev-parse --abbrev-ref HEAD).chomp)
  conf.verbose = options["verbose"]
  puts "$ ballantine diff #{target} #{source}" if conf.verbose

  # validate arguments
  validate(target, source, **options)

  # init instance variables
  init_variables(target, source, **options)

  # check commits
  check_commits(**options)

  # print commits
  print_commits(target, source, **options)
end

#initObject



16
17
18
19
20
21
22
# File 'lib/ballantine/cli.rb', line 16

def init
  conf.init_file(force: options["force"])

  puts "🥃 Initialized ballantine."

  true
end

#versionObject



66
67
68
69
70
# File 'lib/ballantine/cli.rb', line 66

def version
  puts "ballantine version #{Ballantine::VERSION}"

  Ballantine::VERSION
end