Initial implementation of portainer-cli
Ruby CLI tool for interacting with the Portainer API. Supports listing endpoints/stacks/containers/volumes/networks, creating stacks and containers, and opening an interactive exec session in a container via WebSocket. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative 'portainer_cli/version'
|
||||
require_relative 'portainer_cli/config'
|
||||
require_relative 'portainer_cli/client'
|
||||
require_relative 'portainer_cli/commands/base'
|
||||
require_relative 'portainer_cli/commands/configure'
|
||||
require_relative 'portainer_cli/commands/list'
|
||||
require_relative 'portainer_cli/commands/create'
|
||||
require_relative 'portainer_cli/commands/exec'
|
||||
|
||||
module PortainerCli
|
||||
module CLI
|
||||
def self.require_config!(config)
|
||||
return if config.valid?
|
||||
$stderr.puts "Not configured. Run: portainer-cli configure"
|
||||
exit 1
|
||||
end
|
||||
|
||||
HELP = <<~HELP
|
||||
portainer-cli #{PortainerCli::VERSION}
|
||||
|
||||
Usage:
|
||||
portainer-cli configure Set Portainer URL and credentials
|
||||
portainer-cli list endpoints List environments
|
||||
portainer-cli list stacks List stacks
|
||||
portainer-cli list containers <endpoint-id> List containers
|
||||
portainer-cli list volumes <endpoint-id> List volumes
|
||||
portainer-cli list networks <endpoint-id> List networks
|
||||
portainer-cli create stack --endpoint ID --name NAME --file FILE
|
||||
portainer-cli create container --endpoint ID --image IMAGE [--name NAME] [--port h:c] [--env K=V]
|
||||
portainer-cli exec <endpoint-id> <container> Open interactive shell
|
||||
--shell SHELL Shell to use (default: /bin/sh)
|
||||
|
||||
Config file: ~/.portainer-cli/config.yml
|
||||
HELP
|
||||
|
||||
def self.run(argv)
|
||||
config = Config.load
|
||||
cmd = argv.shift&.downcase
|
||||
|
||||
case cmd
|
||||
when 'configure', 'config'
|
||||
Commands::Configure.new(config).run(argv)
|
||||
when 'list', 'ls'
|
||||
require_config!(config)
|
||||
client = Client.new(config)
|
||||
Commands::List.new(config, client).run(argv)
|
||||
when 'create', 'add'
|
||||
require_config!(config)
|
||||
client = Client.new(config)
|
||||
Commands::Create.new(config, client).run(argv)
|
||||
when 'exec', 'shell', 'console'
|
||||
require_config!(config)
|
||||
client = Client.new(config)
|
||||
Commands::Exec.new(config, client).run(argv)
|
||||
when 'version', '--version', '-v'
|
||||
puts "portainer-cli #{PortainerCli::VERSION}"
|
||||
when 'help', '--help', '-h', nil
|
||||
puts HELP
|
||||
else
|
||||
$stderr.puts "Unknown command: #{cmd}"
|
||||
$stderr.puts HELP
|
||||
exit 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user