public
Description: Piston is a utility that eases vendor branch management. This repository is a complete reimplementation of Piston to provide different backends, depending on the repositories and working copies you pistonize from.
Homepage: http://piston.rubyforge.org/
Clone URL: git://github.com/francois/piston.git
commit  46d0ac78350d7a3977cd49c5c268e599480601bc
tree    31bb91a2a620cd53ded56b19eb4c99327b075fd3
parent  ac2278267cb5730fc7126aeb73d6c4bf2759c719
piston / lib / piston / cli.rb
100644 151 lines (131 sloc) 4.235 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
require "main"
require "log4r"
require "piston/version"
require "piston/commands"
 
Main {
  program "piston"
  author "François Beausoleil <francois@teksol.info>"
  version Piston::VERSION::STRING
 
  mixin :standard_options do
    option("verbose", "v") {
      argument_optional
      cast :integer
      default 0
      validate {|value| (0..5).include?(value)}
      description "Verbosity level (0 to 5, 0 being the default)"
    }
    option("quiet", "q") { default false }
    option("force") { default false }
    option("dry-run") { default false }
  end
 
  mixin :revision_or_commit do
    option "revision", "r" do
      argument_required
      default "HEAD"
      description "The revision you wish to operate on"
    end
 
    option "commit" do
      argument_required
      default "HEAD"
      description "The commit you wish to operate on"
    end
 
    def target_revision
      case
      when params["revision"].given?
        params["revision"].value
      when params["commit"].given?
        params["commit"].value
      else
        :head
      end
    end
  end
 
  mode "import" do
    mixin :standard_options
    mixin :revision_or_commit
 
    argument "repository" do
      required
      description "The repository you wish to Pistonize"
    end
 
    argument "directory" do
      optional
      default nil
      description "Where to put the Pistonized repository"
    end
 
    option("lock") do
      default false
      description "Automatically lock down the revision/commit to protect against blanket updates"
    end
 
    logger_level Logger::DEBUG
    def run
      configure_logging!
 
      if params["revision"].given? && params["commit"].given? then
        raise ArgumentError, "Only one of --revision or --commit can be given. Received both."
      end
 
      cmd = Piston::Commands::Import.new(:lock => params["lock"].value,
                                         :verbose => params["verbose"].value,
                                         :quiet => params["quiet"].value,
                                         :force => params["force"].value,
                                         :dry_run => params["dry-run"].value)
      cmd.run(params[:repository].value, self.target_revision, params[:directory].value)
    end
  end
 
  option("version", "v")
 
  def run
    if params["version"].given? || ARGV.first == "version" then
      puts Piston.version_message
      exit_success!
    elsif ARGV.empty?
      puts Piston.version_message
      puts "\nNo mode given. Call with help to find out the available options."
      exit_failure!
    else
      puts "Unrecognized mode: #{ARGV.first.inspect}. Use the help mode to find the available options."
      exit_warn!
    end
  end
 
  def configure_logging!
    Log4r::Logger.root.level = Log4r::INFO
 
    case params["verbose"].value
    when 0
      main_level = Log4r::INFO
      handler_level = Log4r::WARN
      client_level = Log4r::WARN
      client_out_level = Log4r::WARN
      stdout_level = Log4r::INFO
    when 1
      main_level = Log4r::DEBUG
      handler_level = Log4r::INFO
      client_level = Log4r::WARN
      client_out_level = Log4r::WARN
      stdout_level = Log4r::DEBUG
    when 2
      main_level = Log4r::DEBUG
      handler_level = Log4r::DEBUG
      client_level = Log4r::INFO
      client_out_level = Log4r::WARN
      stdout_level = Log4r::DEBUG
    when 3
      main_level = Log4r::DEBUG
      handler_level = Log4r::DEBUG
      client_level = Log4r::DEBUG
      client_out_level = Log4r::INFO
      stdout_level = Log4r::DEBUG
    when 4, 5
      main_level = Log4r::DEBUG
      handler_level = Log4r::DEBUG
      client_level = Log4r::DEBUG
      client_out_level = Log4r::DEBUG
      stdout_level = Log4r::DEBUG
    else
      raise ArgumentError, "Did not expect verbosity to be outside 0..5: #{params["verbose"].value}"
    end
 
    Log4r::Logger.new("main", main_level)
    Log4r::Logger.new("handler", handler_level)
    Log4r::Logger.new("handler::client", client_level)
    Log4r::Logger.new("handler::client::out", client_out_level)
 
    Log4r::StdoutOutputter.new("stdout", :level => stdout_level)
 
    Log4r::Logger["main"].add "stdout"
    Log4r::Logger["handler"].add "stdout"
  end
}