Class: Compote::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/compote/cli.rb,
lib/compote/cli/env.rb,
lib/compote/cli/help.rb,
lib/compote/cli/command.rb,
lib/compote/cli/compose.rb,
lib/compote/cli/version.rb,
lib/compote/cli/commands.rb

Constant Summary collapse

COMPOSE_COMMANDS =
%w()
COMPOTE_COMMANDS =
%w( env help version )

Instance Method Summary collapse

Instance Method Details

#command(key, *arguments) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/compote/cli/command.rb', line 7

def command ( key, *arguments )

  config = load_config

  commands = config.commands

  command = commands[ key ]

  service_name, command_name = key.include?( ':' ) ? key.split( ':' ) : [ nil, key ]

  raise UndefinedCommandError.new service_name: service_name, command_name: command_name, config: config unless command

  arguments = [ *Shellwords.split( command ), *arguments ]

  say "Running compote command \"#{ key }\":"

  if service_name

    run_arguments, command_arguments = split_arguments arguments

    arguments = [ 'run', *run_arguments, service_name, *command_arguments ]

    say Shellwords.join [ 'compote', *arguments ]

    run_compose *arguments

  else

    say Shellwords.join arguments

    environment = config.compose_environment

    exec environment, *arguments

  end

rescue Error => error

  exit_with_error error

end

#commandsObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/compote/cli/commands.rb', line 7

def commands

  config = load_config

  commands = config.commands

  if commands.empty?

    say 'No commands specified'

  else

    say commands.map { | key, command | "#{ key } -> #{ command }" }.join "\n"

  end

rescue Error => error

  exit_with_error error

end

#envObject



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/compote/cli/env.rb', line 7

def env

  compote_config = load_config

  compose_environment = compote_config.compose_environment

  say YAML.dump compose_environment

rescue Error => error

  exit_with_error error

end

#help(*arguments) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/compote/cli/help.rb', line 7

def help ( *arguments )

  if COMPOSE_COMMANDS.include? arguments.first

    exec 'docker-compose', 'help', *arguments

  else

    super *arguments

  end

end

#versionObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/compote/cli/version.rb', line 9

def version

  compote_version = "compote version: #{ Compote::VERSION }"

  compose_version = if options[ :short ]

    "docker-compose version: #{ `docker-compose version --short` }"

  else

    `docker-compose version`

  end

  say compote_version

  say compose_version

end