Class: Mast::Cli
- Inherits:
-
Object
- Object
- Mast::Cli
- Defined in:
- lib/mast/cli.rb
Overview
Manifest Console Command
Constant Summary collapse
- DIGESTS =
[:md5, :sha1, :sha128, :sha256, :sha512]
Instance Attribute Summary collapse
-
#all ⇒ Object
Returns the value of attribute all.
-
#digest ⇒ Object
Returns the value of attribute digest.
-
#dir ⇒ Object
Returns the value of attribute dir.
-
#exclude ⇒ Object
Returns the value of attribute exclude.
-
#file ⇒ Object
Returns the value of attribute file.
-
#ignore ⇒ Object
Returns the value of attribute ignore.
-
#include ⇒ Object
Returns the value of attribute include.
-
#quiet ⇒ Object
Returns the value of attribute quiet.
-
#show ⇒ Object
Returns the value of attribute show.
Class Method Summary collapse
Instance Method Summary collapse
-
#clean ⇒ Object
Clean (or clobber if you prefer) non-manifest files.
-
#diff ⇒ Object
Show diff comparison between listed and actual.
-
#generate ⇒ Object
Default command – output manifest.
-
#help ⇒ Object
Display command help information.
-
#initialize ⇒ Cli
constructor
A new instance of Cli.
-
#list ⇒ Object
List files in manifest file.
-
#new ⇒ Object
Files found, but not listed in manifest.
-
#old ⇒ Object
Files listed in manifest, but not found.
-
#optparse ⇒ Object
Parse command line options.
- #run ⇒ Object
-
#run_command ⇒ Object
Run command.
-
#update ⇒ Object
(also: #up)
Update a MANIFEST file for this package.
- #verify ⇒ Object
Constructor Details
#initialize ⇒ Cli
Returns a new instance of Cli.
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/mast/cli.rb', line 79 def initialize @quiet = false @all = false @file = nil @digest = nil @exclude = [] @include = [] @ignore = [] @command = [] end |
Instance Attribute Details
#all ⇒ Object
Returns the value of attribute all.
74 75 76 |
# File 'lib/mast/cli.rb', line 74 def all @all end |
#digest ⇒ Object
Returns the value of attribute digest.
70 71 72 |
# File 'lib/mast/cli.rb', line 70 def digest @digest end |
#dir ⇒ Object
Returns the value of attribute dir.
75 76 77 |
# File 'lib/mast/cli.rb', line 75 def dir @dir end |
#exclude ⇒ Object
Returns the value of attribute exclude.
73 74 75 |
# File 'lib/mast/cli.rb', line 73 def exclude @exclude end |
#file ⇒ Object
Returns the value of attribute file.
69 70 71 |
# File 'lib/mast/cli.rb', line 69 def file @file end |
#ignore ⇒ Object
Returns the value of attribute ignore.
71 72 73 |
# File 'lib/mast/cli.rb', line 71 def ignore @ignore end |
#include ⇒ Object
Returns the value of attribute include.
72 73 74 |
# File 'lib/mast/cli.rb', line 72 def include @include end |
#quiet ⇒ Object
Returns the value of attribute quiet.
68 69 70 |
# File 'lib/mast/cli.rb', line 68 def quiet @quiet end |
#show ⇒ Object
Returns the value of attribute show.
76 77 78 |
# File 'lib/mast/cli.rb', line 76 def show @show end |
Class Method Details
.run ⇒ Object
62 63 64 |
# File 'lib/mast/cli.rb', line 62 def self.run new.run end |
Instance Method Details
#clean ⇒ Object
Clean (or clobber if you prefer) non-manifest files.
270 271 272 273 274 275 276 277 278 279 |
# File 'lib/mast/cli.rb', line 270 def clean answer = confirm_clean(manifest.cleanlist) case answer.downcase when 'y', 'yes' manifest.clean else report_cancelled('Clean') exit! end end |
#diff ⇒ Object
Show diff comparison between listed and actual.
241 242 243 244 |
# File 'lib/mast/cli.rb', line 241 def diff result = manifest.diff report_difference(result) end |
#generate ⇒ Object
Default command – output manifest.
208 209 210 211 212 213 214 |
# File 'lib/mast/cli.rb', line 208 def generate #if file # update #else manifest.generate #end end |
#help ⇒ Object
Display command help information.
282 283 284 |
# File 'lib/mast/cli.rb', line 282 def help report_help end |
#list ⇒ Object
List files in manifest file.
231 232 233 |
# File 'lib/mast/cli.rb', line 231 def list puts manifest.filelist end |
#new ⇒ Object
Files found, but not listed in manifest.
255 256 257 258 259 260 |
# File 'lib/mast/cli.rb', line 255 def new list = manifest.whatsnew unless list.empty? report_whatsnew(list) end end |
#old ⇒ Object
Files listed in manifest, but not found.
247 248 249 250 251 252 |
# File 'lib/mast/cli.rb', line 247 def old list = manifest.whatsold unless list.empty? report_whatsold(list) end end |
#optparse ⇒ Object
Parse command line options.
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 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/mast/cli.rb', line 123 def optparse opts = GetoptLong.new( # options [ '--file' , '-f', GetoptLong::REQUIRED_ARGUMENT ], [ '--digest' , '-g', GetoptLong::REQUIRED_ARGUMENT ], [ '--exclude', '-x', GetoptLong::REQUIRED_ARGUMENT ], #[ '--include', '-i', GetoptLong::REQUIRED_ARGUMENT ], [ '--ignore' , '-i', GetoptLong::REQUIRED_ARGUMENT ], [ '--all' , '-a', GetoptLong::NO_ARGUMENT ], [ '--dir' , GetoptLong::NO_ARGUMENT ], [ '--show' , '-s', GetoptLong::NO_ARGUMENT ], [ '--quiet' , '-q', GetoptLong::NO_ARGUMENT ], # commands [ '--help' , '-h', GetoptLong::NO_ARGUMENT ], [ '--create' , '-c', GetoptLong::NO_ARGUMENT ], [ '--update' , '-u', GetoptLong::NO_ARGUMENT ], [ '--list' , '-l', GetoptLong::NO_ARGUMENT ], [ '--diff' , '-d', GetoptLong::NO_ARGUMENT ], [ '--new' , '-n', GetoptLong::NO_ARGUMENT ], [ '--old' , '-o', GetoptLong::NO_ARGUMENT ], [ '--verify' , '-v', GetoptLong::NO_ARGUMENT ], [ '--clean' , GetoptLong::NO_ARGUMENT ] ) opts.each do |key, val| case key when '--help' @command << :help when '--create' @command << :create when '--update' @command << :update when '--list' @command << :list #when '--show' # @command << :show when '--diff' @command << :diff when '--new' @command << :new when '--old' @command << :old when '--verify' @command << :verify when '--clean' @command << :clean when '--file' @file = val when '--digest' @digest = val when '--exclude' @exclude << val #when '--include' # @include << val #when '--ignore' # @ignore << val when '--show' @show = true when '--dir' @dir = true when '--all' @all = true when '--quiet' @quiet = true end end #unless args.empty? # if File.file?(args[0]) # opts[:file] = args[0] # opts[:directory] = args[1] if args[1] # else # opts[:directory] = args[0] # opts[:file] = args[1] if args[1] # end #end @include = ARGV.empty? ? nil : ARGV.dup end |
#run ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'lib/mast/cli.rb', line 91 def run begin run_command rescue => err raise err if $DEBUG report err end end |
#run_command ⇒ Object
Run command.
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/mast/cli.rb', line 101 def run_command optparse if @command.size > 1 raise ArgumentError, "Please issue only one command." end case @command.first when :help then help when :create then generate when :update then update when :list then list #when :show then show when :diff then diff when :new then new when :old then old when :verify then verify when :clean then clean else generate end end |
#update ⇒ Object Also known as: up
Update a MANIFEST file for this package.
218 219 220 221 222 223 224 225 226 |
# File 'lib/mast/cli.rb', line 218 def update begin file = manifest.update rescue NoManifestError => e puts e. exit -1 end report_updated(file) end |
#verify ⇒ Object
263 264 265 266 267 |
# File 'lib/mast/cli.rb', line 263 def verify check = manifest.verify report_verify(check) exit -1 unless check end |