Class: Basketcase

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/basketcase.rb,
lib/basketcase/utils.rb,
lib/basketcase/command.rb,
lib/basketcase/ls_command.rb,
lib/basketcase/help_command.rb,
lib/basketcase/update_command.rb

Defined Under Namespace

Modules: Utils Classes: AddCommand, AutoCheckinCommand, AutoCommand, AutoSyncCommand, AutoUncheckoutCommand, CheckinCommand, CheckoutCommand, Command, DiffCommand, DirectoryModificationCommand, ElementStatus, HelpCommand, LogCommand, LsCoCommand, LsCommand, MoveCommand, RemoveCommand, TargetList, UncheckoutCommand, UpdateCommand, UsageException, VersionTreeCommand

Constant Summary collapse

VERSION =
'1.1.0'
DefaultListener =

Object responsible for nice fomatting of output

lambda do |element|
  printf("%-7s %-15s %s\n", element.status,
    element.base_version, element.path)
end

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils

#mkpath

Class Attribute Details

.usageObject (readonly)

Returns the value of attribute usage.



693
694
695
# File 'lib/basketcase.rb', line 693

def usage
  @usage
end

Class Method Details

.command(command_class, names) ⇒ Object



683
684
685
686
# File 'lib/basketcase.rb', line 683

def command(command_class, names)
  names.each { |name| @registry[name] = command_class }
  @usage << "    % #{names.join(', ')}\n"
end

.command_class(name) ⇒ Object



688
689
690
691
# File 'lib/basketcase.rb', line 688

def command_class(name)
  return name if Class === name
  @registry[name] || raise(UsageException, "Unknown command: #{name}")
end

Instance Method Details

#do(*args) ⇒ Object



750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
# File 'lib/basketcase.rb', line 750

def do(*args)
  @args = args
  begin
    sync_io
    handle_global_options
    raise UsageException, "no command specified" if @args.empty?
    define_standard_ignore_patterns
    run(*@args)
  rescue UsageException => usage
    $stderr.puts "ERROR: #{usage.message}"
    $stderr.puts
    $stderr.puts "try 'basketcase help' for usage info"
    exit(1)
  end
end

#handle_global_optionsObject



736
737
738
739
740
741
742
743
744
745
746
747
748
# File 'lib/basketcase.rb', line 736

def handle_global_options
  while /^-/ === @args[0]
    option = @args.shift
    case option
    when '--test', '-t'
      @test_mode = true
    when '--debug', '-d'
      @debug_mode = true
    else
      raise UsageException, "Unrecognised global argument: #{option}"
    end
  end
end

#ignored?(path) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
53
54
55
56
# File 'lib/basketcase.rb', line 50

def ignored?(path)
  path = Pathname(path).expand_path
  require_ignore_patterns_for(path.parent)
  @ignore_patterns.detect do |pattern|
    File.fnmatch(pattern, path, File::FNM_PATHNAME | File::FNM_DOTMATCH)
  end
end

#just_testing?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/basketcase.rb', line 44

def just_testing?
  @test_mode
end

#log_debug(msg) ⇒ Object



39
40
41
42
# File 'lib/basketcase.rb', line 39

def log_debug(msg)
  return unless @debug_mode
  $stderr.puts(msg)
end

#make_command(name) ⇒ Object



720
721
722
# File 'lib/basketcase.rb', line 720

def make_command(name)
  Basketcase.command_class(name).new(self)
end

#run(name, *args, &block) ⇒ Object



724
725
726
727
728
729
# File 'lib/basketcase.rb', line 724

def run(name, *args, &block)
  command = make_command(name)
  command.accept_args(args) if args
  command.listener = block if block_given?
  command.execute
end

#sync_ioObject



731
732
733
734
# File 'lib/basketcase.rb', line 731

def sync_io
  $stdout.sync = true
  $stderr.sync = true
end

#usageObject



716
717
718
# File 'lib/basketcase.rb', line 716

def usage
  Basketcase.usage
end