lib/mast/cli.rb in mast-1.3.0 vs lib/mast/cli.rb in mast-1.4.0

- old
+ new

@@ -1,52 +1,5 @@ -# mast v1.0.0 -# -# Usage: -# mast [command] [options...] -# -# The manifest listing tool is used to list, create or update a -# manifest for a directory (eg. to define a "package"), or compare -# a manifest to actual directory contents. Mast is part of the -# ProUtils set of tools. -# -# When no command is given, a manifest is dumped to standard out. -# If --file is specified, it will generate to that file instead. -# -# Examples: -# mast -# mast -u -f PUBLISH -# -# Commands: -# -c --create Generate a new manifest. (default) -# -u --update Update an existing manifest. -# -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 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. -# -d --dir When creating a list include directory paths; by default -# only files are listed. -# -b --bang Produce new manifest but using options from the bang line of the manifest file. -# -f --file PATH Path to manifest file. This applies to comparison commands. -# If not given then the file matching 'MANIFEST', case-insensitive -# and with an optional '.txt' extension, in the current directory -# is used. If the path of the manifest file is anything else then -# the --file option must be specified. -# -g --digest TYPE Include crytographic 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. -# -i --ignore PATH Exclude a file or dir from the manifest matching against -# an entries basename. You can use --ignore repeatedly. -# -q --quiet Suppress any extraneous output. - require 'mast' require 'optparse' module Mast @@ -115,70 +68,81 @@ when :diff then diff when :new then new when :old then old when :verify then verify when :clean then clean + when :recent then recent else generate end end # Parse command line options. def option_parser OptionParser.new do |opt| - opt.on "--file", "-f FILE" do |file| + opt.on "-f", "--file FILE", "Path to manifest file. Looks for file matching /MANIFEST(|.txt)/i by default." do |file| @options[:file] = file end - opt.on "--digest", "-g TYPE" do |digest| + opt.on "-g", "--digest TYPE", "Include cryptographic signature. Type can be either md5, sha1, sha128, sha256, or sha512." do |digest| @options[:digest] = digest end - opt.on "--exclude", "-x GLOB" do |glob| + opt.on "-x", "--exclude GLOB", "Exclude file or dir from the manifest matching against full pathname. Can be used repeatedly." do |glob| @options[:exclude] << glob end - opt.on "--ignore", "-i GLOB" do |glob| + opt.on "-i", "--ignore GLOB", + "Exclude file or dir from manifest matching against an entry's basename. Can be used repeatedly." do |glob| @options[:ignore] << glob end - opt.on "--all", "-a" do |bool| + opt.on "-a", "--all", "Include all files. This deactivates default exclusions so it is possible to make complete list of all contents." do |bool| @options[:all] = true end - opt.on "--bang", "-b" do |bool| + opt.on "--bang", "-b", "Generate manifest using the options from the bang line of the manifest file." do |bool| @options[:bang] = true end - opt.on "--dir", "-d" do |bool| + opt.on "--dir", "-d", "When creating a list include directory paths; by default only files are listed." do |bool| @options[:dir] = bool end - #opt.on "--quiet", "-q", "" do |bool| - # @quiet = bool - #end - opt.on "--create", "-c" do + opt.on "--[no-]head", "Suppress mast header from output." do |bool| + @options[:headless] = !bool + end + opt.on "-c", "--create", "Generate a new manifest. (default)" do @command << :create end - opt.on "--update", "-u" do + opt.on "-u", "--update", "Update an existing manifest." do @command << :update end - opt.on "--list", "-l" do + opt.on "-l", "--list", "List the files given in the manifest file. (Use -f to specify an alternate file.)" do @command << :list end - opt.on "--diff", "-D" do + opt.on "-D", "--diff", "Diff manifest file against actual." do @command << :diff end - opt.on "--new", "-n" do + opt.on "-n", "--new", "List existent files that are not given in the manifest." do @command << :new end - opt.on "--old", "-o" do + opt.on "-o", "--old", "List files given in the manifest but are non-existent." do @command << :old end - opt.on "--verify", "-v" do + opt.on "-v", "--verify", "Verify that a manifest matches actual." do @command << :verify end - opt.on "--clean" do + opt.on "--clean", "Remove non-manifest files. (Will ask for confirmation first.)" do @command << :clean end - opt.on "--help" do + opt.on "-r", "--recent", "Verify that a manifest is more recent than actual." do + @command << :recent + end + opt.on "-h", "--help", "Display this help message." do @command << :help end - opt.on "--debug" do + opt.on "-H" do + puts opt; exit + end + opt.on "-q", "--quiet", "Suppress all extraneous output." do + @quiet = true + end + opt.on "--debug", "Run in debug mode." do $DEBUG = true end end end @@ -191,17 +155,22 @@ #end end # Update a MANIFEST file for this package. def update - begin - file = manifest.update - rescue NoManifestError => e - puts e.message - exit -1 + if manifest.verify + else + begin + diff = manifest.diff + file = manifest.update + rescue Manifest::NoManifestError => e + puts e.message + exit -1 + end + report_difference(diff) + #report_updated(file) end - report_updated(file) end alias_method :up, :update # List files in manifest file. @@ -253,10 +222,24 @@ report_cancelled('Clean') exit! end end + # Verify manifest, then check to see that it is not older than files + # it lists. + def recent + check = manifest.verify + if !check + report_verify(check) + exit -1 + end + if !FileUtils.uptodate?(manifest.file, manifest.filelist) + report_outofdate + exit -1 + end + end + # Display command help information. def help report_help end @@ -343,17 +326,16 @@ end # Show help. def report_help doc = false - File.readlines(__FILE__).each do |line| - line = line.strip - break if doc && line.empty? - next if line =~ /^#!/ - next if line.empty? - puts line[1..-1].sub(/^\ \ /,'') - doc = true + man_page = File.dirname(__FILE__) + '/../../man/man1/mast.1' + ronn_file = File.dirname(__FILE__) + '/../../man/man1/mast.1.ronn' + if File.exist?(man_page) + system "man #{man_page}" || puts(File.read(ronn_file)) + else + puts option_parser end end # Report missing manifest file. def report_manifest_missing @@ -380,9 +362,14 @@ if check report "Manifest is good." else report "Manifest is bad!" end + end + + # + def report_outofdate + report "Manifest is older than listed file(s)." end # def ask(prompt=nil) $stdout << "#{prompt}"