Class: Appril::CLI

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/appril-cli.rb,
lib/appril-cli.rb,
lib/appril-cli/docker.rb,
lib/appril-cli/update.rb,
lib/appril-cli/helpers.rb,
lib/appril-cli/install.rb,
lib/appril-cli/version.rb,
lib/appril-cli/assertions.rb,
lib/appril-cli/docker/build.rb,
lib/appril-cli/docker/update.rb,
lib/appril-cli/docker/install.rb

Defined Under Namespace

Modules: Assertions, Helpers Classes: Docker, Install, Update

Constant Summary collapse

BASE_DIR =
Pathname.new(File.expand_path('../..', __FILE__))
APP_DIR =
BASE_DIR / 'app'
DOCKER_DIR =
BASE_DIR / 'docker'
WORKING_DIR =
Pathname.new(Dir.pwd)
VERSION =
'0.4.1'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#create_dirname_for, #expanded_path, #extract_namespace, #fatal_error!, #format_error, #make_executable

Constructor Details

#initialize(args) ⇒ CLI

Returns a new instance of CLI.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/appril-cli.rb', line 43

def initialize args

  if args.empty? || args[0] == '-h'
    return usage
  end

  if args[0] == '-v'
    return puts VERSION
  end

  opts, args = args.partition {|a| a =~ /\A\-/}

  case command = args[0]
  when 'i', 'install'
    Install.new(Pathname.new(args[1] || WORKING_DIR))

  when 'u', 'update'
    Update.new(Pathname.new(args[1] || WORKING_DIR))


  when 'd', 'docker'
    path = Pathname.new(args[2] || WORKING_DIR)

    case subcommand = args[1]
    when 'i', 'install'
      Docker::Install.new(path)

    when 'u', 'update'
      Docker::Update.new(path)

    when 'b', 'build'
      Docker::Build.new(path, {
        update_runner_only: opts.include?('-u'),
        push_opted: opts.include?('-p')
      })
    else
      puts format_error("Unknown subcommand #{subcommand}")
      usage
    end
  else
    puts format_error("Unknown command #{command}")
    usage
  end
end

Class Method Details

.run(cmd) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/appril-cli.rb', line 14

def self.run cmd
  puts "", "$ #{cmd}"
  PTY.spawn cmd do |r, w, pid|
    begin
      r.sync
      r.each_char do |char|
        print(char)
      end
    rescue Errno::EIO => e
      # simply ignoring this
    ensure
      Process.wait(pid)
    end
  end
end

Instance Method Details

#usageObject



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/appril-cli.rb', line 88

def usage
  puts "
  Arguments in round brackets are required.
  Arguments in square brackets are optional.

  All operations accepts a path as last argument.
  If no path given current folder will be used.


  === Install a new app ===
  $ appril (install || i) [path]

  === Update existing app ===
  $ appril (update || u) [path]

  === Install Docker builder ===
  $ appril (docker || d) (install || i) [path]

  === Update Docker builder ===
  $ appril (docker || d) (update || u) [path]

  === Build Docker image and install run script ===
  $ appril (docker || d) (build || b) [path] [-u] [-p]
  * If -u option provided it will only update the run script without building the image.
  * If -p option provided it will try to push the image to Docker registry after successful build.

  === Usage ===
  $ appril [-h]

  === Version ===
  $ appril [-v]
  ".split("\n").map {|l| "\t" + l.strip}.join("\n")
end