Class: RubynCode::CLI::Commands::Budget

Inherits:
Base
  • Object
show all
Defined in:
lib/rubyn_code/cli/commands/budget.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

aliases, all_names, hidden?

Class Method Details

.command_nameObject



7
# File 'lib/rubyn_code/cli/commands/budget.rb', line 7

def self.command_name = '/budget'

.descriptionObject



8
# File 'lib/rubyn_code/cli/commands/budget.rb', line 8

def self.description = 'Show or set session budget (/budget [amount])'

Instance Method Details

#execute(args, ctx) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rubyn_code/cli/commands/budget.rb', line 10

def execute(args, ctx)
  amount = args.first

  if amount
    ctx.renderer.info("Session budget set to $#{amount}")
    { action: :set_budget, amount: amount.to_f }
  else
    remaining = ctx.budget_enforcer.remaining_budget
    ctx.renderer.info("Remaining budget: $#{format('%.4f', remaining)}")
  end
end