Skip to content

Commit

Permalink
Show org and app on every command (#94)
Browse files Browse the repository at this point in the history
* Show org and app on every command exclude info, version, maintenance, env, ps, and latest_image
  • Loading branch information
ahangarha authored Nov 14, 2023
1 parent 3423aff commit 46e4569
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lib/command/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class Base # rubocop:disable Metrics/ClassLength
EXAMPLES = ""
# If `true`, hides the command from `cpl help`
HIDE = false
# Whether or not to show key information like ORG and APP name in commands
WITH_INFO_HEADER = true

NO_IMAGE_AVAILABLE = "NO_IMAGE_AVAILABLE"

Expand Down
1 change: 1 addition & 0 deletions lib/command/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Env < Base
LONG_DESCRIPTION = <<~DESC
- Displays app-specific environment variables
DESC
WITH_INFO_HEADER = false

def call
cp.fetch_gvc!.dig("spec", "env").map do |prop|
Expand Down
1 change: 1 addition & 0 deletions lib/command/info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Info < Base # rubocop:disable Metrics/ClassLength
cpl info -a $APP_NAME
```
EX
WITH_INFO_HEADER = false

def call
@missing_apps_workloads = {}
Expand Down
1 change: 1 addition & 0 deletions lib/command/latest_image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class LatestImage < Base
LONG_DESCRIPTION = <<~DESC
- Displays the latest image name
DESC
WITH_INFO_HEADER = false

def call
puts latest_image
Expand Down
1 change: 1 addition & 0 deletions lib/command/maintenance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Maintenance < Base
- Optionally specify the maintenance workload through `maintenance_workload` in the `.controlplane/controlplane.yml` file (defaults to 'maintenance')
- Maintenance mode is only supported for domains that use path based routing mode and have a route configured for the prefix '/' on either port 80 or 443
DESC
WITH_INFO_HEADER = false

def call # rubocop:disable Metrics/MethodLength
one_off_workload = config[:one_off_workload]
Expand Down
1 change: 1 addition & 0 deletions lib/command/no_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class NoCommand < Base
- Called when no command was specified
DESC
HIDE = true
WITH_INFO_HEADER = false

def call
if config.options[:version]
Expand Down
1 change: 1 addition & 0 deletions lib/command/ps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Ps < Base
cpl ps -a $APP_NAME -w $WORKLOAD_NAME
```
EX
WITH_INFO_HEADER = false

def call
cp.fetch_gvc!
Expand Down
1 change: 1 addition & 0 deletions lib/command/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Version < Base
- Displays the current version of the CLI
- Can also be done with `cpl --version` or `cpl -v`
DESC
WITH_INFO_HEADER = false

def call
puts Cpl::VERSION
Expand Down
6 changes: 3 additions & 3 deletions lib/core/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ class Config # rubocop:disable Metrics/ClassLength
def initialize(args, options)
@args = args
@options = options
@org = options[:org]
@org = options[:org]&.strip
@org_comes_from_env = true if ENV.fetch("CPLN_ORG", nil)
@app = options[:app]
@app = options[:app]&.strip

load_app_config
load_apps
Expand Down Expand Up @@ -81,7 +81,7 @@ def pick_current_config(app_name, app_options)

return if @org

@org = current.fetch(:cpln_org) if current.key?(:cpln_org)
@org = current.fetch(:cpln_org)&.strip if current.key?(:cpln_org)
ensure_current_config_org!(app_name)
end

Expand Down
18 changes: 18 additions & 0 deletions lib/cpl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def self.all_base_commands
long_description = command_class::LONG_DESCRIPTION
examples = command_class::EXAMPLES
hide = command_class::HIDE || deprecated
with_info_header = command_class::WITH_INFO_HEADER

long_description += "\n#{examples}" if examples.length.positive?

Expand Down Expand Up @@ -178,6 +179,8 @@ def self.all_base_commands
begin
config = Config.new(args, options)

show_info_header(config) if with_info_header

command_class.new(config).call
rescue RuntimeError => e
::Shell.abort(e.message)
Expand All @@ -186,6 +189,21 @@ def self.all_base_commands
rescue StandardError => e
::Shell.abort("Unable to load command: #{e.message}")
end

private

def show_info_header(config)
rows = {}
rows["ORG"] = config.org || "NOT PROVIDED!"
rows["APP"] = config.app || "NOT PROVIDED!"

rows.each do |key, value|
puts "#{key}: #{value}"
end

# Add a newline after the info header
puts
end
end
end

Expand Down

0 comments on commit 46e4569

Please sign in to comment.