Module: Svp::CLI

Defined in:
lib/svp/cli.rb

Constant Summary collapse

ABBREVIATIONS =
{
  "ci" => "commit",
  "co" => "checkout",
  "cp" => "copy",
  "del" => "delete",
  "remove" => "delete",
  "rm" => "delete",
  "di" => "diff",
  "st" => "status",
  "stat" => "status",
  "up" => "update",
  "mv" => "move",
  "ren" => "move",
  "rename" => "rename"
}

Class Method Summary collapse

Class Method Details

.execute!Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/svp/cli.rb', line 25

def self.execute!
  work_dir = ENV["PWD"]
  command = ARGV.first
  args = ARGV[1..-1]
  config = nil

  command = ABBREVIATIONS[command] || command

  if command == "version"
    puts "svp, version #{VERSION::STRING}"
    puts "Copyright (c) 2006 RedHill Consulting, Pty. Ltd.  All rights reserved."
    exit
  end

  if command == "checkout"
    depot_uri = args[0]
    work_dir = File.join(work_dir, args[1] || File.basename(depot_uri))
    config = { "revision" => 0, "depot_uri" => depot_uri, "ignores" => [] }
    command = "update"
  end

  svp_dir = File.join(work_dir, ".svp")
  config_file = File.join(svp_dir, "config.yml")

  config = YAML::load(IO.read(config_file)) unless config

  workspace = Workspace.new(URI.parse(config["depot_uri"]), work_dir, svp_dir, config["revision"], config["ignores"])
  workspace.send(command.to_sym, *args)
  config["revision"] = workspace.revision
  config["ignores"] = workspace.ignores

  File.open(config_file, "w") { |io| YAML::dump(config, io) }
end