Skip to content

Commit

Permalink
Merge pull request #34 from opus-codium/minor_cli_fixes
Browse files Browse the repository at this point in the history
CLI: Fix `colt tasks show` when using it with long task names
  • Loading branch information
neomilium authored Oct 29, 2024
2 parents 46036af + 2d07c08 commit 1decd9d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 10 additions & 3 deletions lib/choria/colt/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ def show(*tasks_names)
default: 'summary'
define_targets_and_filters_options
def status(task_id)
supported_styles = %i[summary continous]
raise Thor::Error, "Invalid style: '#{options['style']}' (available: #{supported_styles})" unless supported_styles.include? options['style'].to_sym
validate_style_option

targets, targets_with_classes = extract_targets_and_filters_from_options

Expand Down Expand Up @@ -131,6 +130,11 @@ def formatter
@formatter ||= Formatter.new(colored: $stdout.tty?)
end

def validate_style_option
supported_styles = %i[summary continous]
raise Thor::Error, "Invalid style: '#{options['style']}' (available: #{supported_styles.map(&:to_s)})" unless supported_styles.include? options['style'].to_sym
end

def extract_task_parameters_from_args(args)
parameters = args.grep(/^\w+=/)
args.reject! { |arg| arg =~ /^\w+=/ }
Expand Down Expand Up @@ -170,9 +174,12 @@ def extract_targets_from_options
def show_tasks_summary(tasks)
tasks.reject! { |_task, metadata| metadata['metadata']['private'] }

task_name_max_size = 0
tasks.each { |task, _metadata| task_name_max_size = [task_name_max_size, task.size].max }

puts <<~OUTPUT
#{pastel.title 'Tasks'}
#{tasks.map { |task, metadata| "#{task}#{' ' * (60 - task.size)}#{metadata['metadata']['description']}" }.join("\n").gsub(/^/, ' ')}
#{tasks.map { |task, metadata| "#{task}#{' ' * (task_name_max_size + 4 - task.size)}#{metadata['metadata']['description']}" }.join("\n").gsub(/^/, ' ')}
OUTPUT
end

Expand Down
4 changes: 2 additions & 2 deletions lib/choria/orchestrator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ def tasks_support
def run(task, targets: nil, targets_with_classes: nil, verbose: false)
rpc_client.progress = verbose
discover(targets: targets, targets_with_classes: targets_with_classes)
raise DiscoverError, 'No requests sent, no nodes discovered' if rpc_client.discover.size.zero?
raise DiscoverError, 'No requests sent, no nodes discovered' if rpc_client.discover.empty?

task.run
end

def discover(targets: nil, targets_with_classes: nil)
logger.debug "Targets: #{targets.nil? ? 'all' : targets})"
logger.debug "Targets: #{targets.nil? ? 'all' : targets}"
targets&.each { |target| rpc_client.identity_filter target }

unless targets_with_classes.nil?
Expand Down

0 comments on commit 1decd9d

Please sign in to comment.