Class: Captive::CLI
- Inherits:
-
Thor
- Object
- Thor
- Captive::CLI
- Includes:
- CLIDependencies
- Defined in:
- lib/captive/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
- #completions(shell) ⇒ Object
- #console(app) ⇒ Object
- #login ⇒ Object
- #logs(app) ⇒ Object
- #run_cmd(app, *cmd) ⇒ Object
- #version ⇒ Object
- #whoami ⇒ Object
Class Method Details
.exit_on_failure? ⇒ Boolean
20 |
# File 'lib/captive/cli.rb', line 20 def self.exit_on_failure? = true |
.start(args = ARGV, config = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/captive/cli.rb', line 22 def self.start(args = ARGV, config = {}) args = [ "help", args.first ] if args.length == 2 && %w[--help -h].include?(args.last) case UpdateChecker.new.check when :blocked warn "Version #{VERSION} n'est plus supportée. Mettez à jour : brew upgrade captive-studio/tap/captive-cli" exit 1 when :update_available warn "⚠ Nouvelle version disponible. Mettez à jour : brew upgrade captive-studio/tap/captive-cli" end super rescue AuthError, NotAuthenticatedError, NoTtyError => e warn e. exit 1 rescue StandardError => e warn "Une erreur inattendue s'est produite : #{e.}" warn "Si le problème persiste, contacte l'équipe Captive." exit 1 end |
Instance Method Details
#completions(shell) ⇒ Object
118 119 120 121 122 123 124 |
# File 'lib/captive/cli.rb', line 118 def completions(shell) case shell when "bash" then print ShellCompletions.bash when "zsh" then print ShellCompletions.zsh else abort "Shell non supporté : #{shell}. Utilise bash ou zsh." end end |
#console(app) ⇒ Object
83 84 85 |
# File 'lib/captive/cli.rb', line 83 def console(app) Commands::Console.new(trail: trail, one_off: Commands::OneOffSession.new(kubectl: kubectl)).run(app) end |
#login ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/captive/cli.rb', line 64 def login Commands::UserLogin.new( github: GithubDeviceFlow.new, cluster: ClusterEndpoint.new, token_path: File.("~/.config/captive/token"), kubeconfig_path: File.("~/.config/captive/kubeconfig") ).call puts "Authentifié avec succès." end |
#logs(app) ⇒ Object
160 161 162 163 164 165 166 167 168 |
# File 'lib/captive/cli.rb', line 160 def logs(app) from = parse_time([:from]) to = parse_time([:to]) Commands::Logs.new(kubectl: kubectl).run( app, follow: [:follow], container: [:container], worker: [:worker], lines: [:lines], from: from, to: to, raw: [:raw] ) end |
#run_cmd(app, *cmd) ⇒ Object
100 101 102 103 |
# File 'lib/captive/cli.rb', line 100 def run_cmd(app, *cmd) exit_code = Commands::Run.new(kubectl: kubectl, trail: trail).run(app, *cmd) exit(exit_code) if exit_code && exit_code != 0 end |
#version ⇒ Object
55 |
# File 'lib/captive/cli.rb', line 55 def version = puts VERSION |
#whoami ⇒ Object
106 107 108 |
# File 'lib/captive/cli.rb', line 106 def whoami puts kubectl.run("auth", "whoami") end |