Class: CastCaster::CLI

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

Constant Summary collapse

IMAGES =
CastCaster::IMAGES

Instance Method Summary collapse

Instance Method Details

#configObject



35
36
37
38
39
40
# File 'lib/castcaster/cli.rb', line 35

def config
  cfg = Config.new.load
  engine_name = options[:engine] || cfg['engine']
  engine = Engines.create(engine_name, cfg)
  say engine.config_preview
end

#deployObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/castcaster/cli.rb', line 46

def deploy
  cfg = Config.new.load
  cfg['enable_traefik'] = true if options[:with_traefik]
  engine = create_engine
  channels = Channel.all
  case options[:mode]
  when 'swarm'
    dpl = Deploy::Swarm.new(engine, channels, cfg)
  else
    dpl = Deploy::Compose.new(engine, channels)
    dpl.with_traefik = true if options[:with_traefik]
  end
  path = dpl.write
  say_status :created, path
end

#doctorObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/castcaster/cli.rb', line 65

def doctor
  checks = {
    'Ruby'          => RUBY_VERSION,
    'Docker'        => system('docker --version >/dev/null 2>&1') ? `docker --version`.strip : 'not found',
    'Docker Compose'=> system('docker compose version >/dev/null 2>&1') ? `docker compose version`.strip : 'not found',
    'config.yml'    => File.exist?('castcaster.yml') ? 'ok' : 'not found (run init)'
  }
  IMAGES.each do |name, tag|
    if system("docker image inspect #{tag} >/dev/null 2>&1")
      checks[name] = 'available'
    else
      checks[name] = "docker pull #{tag}"
    end
  end
  checks.each { |name, status| say "#{name.ljust(14)} #{status}" }
end

#initObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/castcaster/cli.rb', line 11

def init
  config = Config.new
  config.ensure_project_dirs
  token = config.ensure_token

  cfg = Config::DEFAULTS.dup
  cfg['engine'] = options[:engine] if options[:engine]
  cfg['project_dir'] = Dir.pwd
  config.save(cfg)

  say_status :created, "castcaster.yml"
  say_status :created, "castcaster.token"
  say_status :created, "channels/"
  say_status :created, "hls/"
  say ''
  say "  CastCaster v#{VERSION} initialized"
  say "  Engine: #{cfg['engine']}"
  say ''
  say "  Edit channels/, then run:"
  say "    docker compose up -d"
end

#versionObject



86
87
88
# File 'lib/castcaster/cli.rb', line 86

def version
  say VERSION
end