Class: RubynCode::CLI::Commands::Diff

Inherits:
Base
  • Object
show all
Defined in:
lib/rubyn_code/cli/commands/diff.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/diff.rb', line 7

def self.command_name = '/diff'

.descriptionObject



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

def self.description = 'Show git diff (staged, unstaged, or vs branch)'

Instance Method Details

#execute(args, ctx) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rubyn_code/cli/commands/diff.rb', line 10

def execute(args, ctx)
  target = args.first || 'unstaged'

  cmd = case target
        when 'staged'   then 'git diff --cached'
        when 'unstaged' then 'git diff'
        else "git diff #{target}...HEAD"
        end

  output = `cd #{ctx.project_root} && #{cmd} 2>&1`

  if output.strip.empty?
    ctx.renderer.info("No changes (#{target}).")
  else
    puts output
  end
end