lib/mast/cli.rb in mast-1.0.0 vs lib/mast/cli.rb in mast-1.1
- old
+ new
@@ -16,33 +16,35 @@
# mast -u -f PUBLISH
#
# Commands:
# -c --create Generate a new manifest. (default)
# -u --update Update an existing manifest.
-# -l --list List the files give in the manifest file. (Use -f to specify an alternate file.)
-# -s --show Show all files that would appear in the manifest file if it were updated.
+# -l --list List the files given in the manifest file. (Use -f to specify an alternate file.)
# -d --diff Diff manifest file against actual.
# -n --new List existant files that are not given in the manifest.
# -o --old List files given in the manifest but are non-existent.
# --clean Remove non-manifest files. (Will ask for confirmation first.)
-# -v --verify (TODO) Verify that a manifest matches actual.
+# -v --verify Verify that a manifest matches actual.
# -h --help Display this help message.
#
# Options:
# -a --all Include all files. This deactivates deafult exclusions
# so it is possible to make complete list of all contents.
+# --dir When creating a list include directory paths; by default
+# only files are listed.
+# -s --show Show files using the options from the manifest file.
# -f --file PATH Path to manifest file. When using update command, if not
# given then the file matching 'MANIFEST', case-insensitive
# and with an optional '.txt' extension, will be looked for
# in the current directory. If the path of the manifest file
# is anything else then --file option must be specified.
# -g --digest TYPE Include crytogrpahic signiture. Type can be either
# md5, sha1, sha128, sha256, or sha512.
# -x --exclude PATH Exclude a file or dir from the manifest matching against
# full pathname. You can use --exclude repeatedly.
# --ignore PATH Exclude a file or dir from the manifest matching against
-# an extires basename. You can use --ignore repeatedly.
+# an entries basename. You can use --ignore repeatedly.
# -q --quiet Suppress extraneous output.
require 'mast'
# both of these can be replaced by using Clio instead.
@@ -68,10 +70,12 @@
attr_accessor :digest
attr_accessor :ignore
attr_accessor :include
attr_accessor :exclude
attr_accessor :all
+ attr_accessor :dir
+ attr_accessor :show
#
def initialize
@quiet = false
@all = false
@@ -81,22 +85,32 @@
@include = []
@ignore = []
@command = []
end
- # Run command.
+ #
def run
+ begin
+ run_command
+ rescue => err
+ raise err if $DEBUG
+ report err
+ end
+ end
+
+ # Run command.
+ 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 :show then show
when :diff then diff
when :new then new
when :old then old
when :verify then verify
when :clean then clean
@@ -111,19 +125,20 @@
# options
[ '--file' , '-f', GetoptLong::REQUIRED_ARGUMENT ],
[ '--digest' , '-g', GetoptLong::REQUIRED_ARGUMENT ],
[ '--exclude', '-x', GetoptLong::REQUIRED_ARGUMENT ],
#[ '--include', '-i', GetoptLong::REQUIRED_ARGUMENT ],
- [ '--ignore', 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 ],
- [ '--show' , '-s', 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 ]
@@ -137,12 +152,12 @@
@command << :create
when '--update'
@command << :update
when '--list'
@command << :list
- when '--show'
- @command << :show
+ #when '--show'
+ # @command << :show
when '--diff'
@command << :diff
when '--new'
@command << :new
when '--old'
@@ -160,10 +175,14 @@
@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
@@ -211,14 +230,14 @@
# List files in manifest file.
def list
puts manifest.filelist
end
- # List files in manifest file.
- def show
- puts manifest.showlist
- end
+ #
+ #def show
+ # puts manifest.showlist
+ #end
# Show diff comparison between listed and actual.
def diff
result = manifest.diff
report_difference(result)
@@ -280,11 +299,11 @@
#)
end
# Options for Manifest class taken from commandline arguments.
def manifest_options
- { :file=>file, :digest=>digest, :exclude=>exclude, :ignore=>ignore, :all=>all, :include=>include }
+ { :file=>file, :digest=>digest, :exclude=>exclude, :ignore=>ignore, :all=>all, :dir=>dir, :include=>include, :show=>show }
end
# Quiet opertation?
def quiet?
@quiet
@@ -300,23 +319,28 @@
def confirm_clobber(list)
puts list.join("\n")
ask("The above files will be removed. Continue?", "yN")
end
+ #
+ def report(message)
+ $stderr << "#{message}\n" unless quiet?
+ end
+
# Report manifest created.
def report_created(file)
file = File.basename(file)
- puts "#{file} created." unless quiet?
+ report "#{file} created."
end
# Report manifest updated.
def report_updated(file)
if file
file = File.basename(file)
- puts "#{file} updated." unless quiet?
+ report "#{file} updated."
else
- puts "Manifest file doesn't exit."
+ report "Manifest file doesn't exit."
end
end
# Display diff between file and actual.
#--
@@ -339,11 +363,11 @@
# Report missing manifest file.
def report_whatsnew(list)
puts list.join("\n")
end
- # Report missing manifest file.
+ #
def report_whatsold(list)
puts list.join("\n")
end
# Show help.
@@ -359,33 +383,33 @@
end
end
# Report missing manifest file.
def report_manifest_missing
- puts "No manifest file."
+ report "No manifest file."
end
# Report action cancelled.
def report_cancelled(action)
- puts "#{action} cancelled."
+ report "#{action} cancelled."
end
# Report manifest overwrite.
def report_overwrite(manifest)
- puts "#{manifest.filename} already exists."
+ report "#{manifest.filename} already exists."
end
# Warn that a manifest already exist higher in this hierarchy.
def report_warn_shadowing(manifest)
- puts "Shadowing #{manifest.file}."
+ report "Shadowing #{manifest.file}."
end
#
def report_verify(check)
if check
- puts "Manifest if good."
+ report "Manifest if good."
else
- puts "Manifest if bad!"
+ report "Manifest if bad!"
end
end
end
end