Class: Prune::CommandLineInterface
- Inherits:
-
Object
- Object
- Prune::CommandLineInterface
- Defined in:
- lib/prune/cli.rb
Overview
The command-line interface for prune is the primary way to interact with it, although it can be invoked programatically as well.
This class defines the arguments and options taken by Prune and how it reacts to various forms of command-line input.
Constant Summary collapse
- DEFAULT_OPTIONS =
{ :verbose => false, :did_work => false, :dry_run => false, :prompt => true, :archive => true, :configure => false }
Class Method Summary collapse
Class Method Details
.make_parser(options) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/prune/cli.rb', line 15 def self.make_parser( ) OptionParser.new do |opts| opts. = "Usage: prune [options] folder" opts.on( "-v", "--verbose", "Prints much more frequently during execution about what it's doing." ) { [:verbose] = true } opts.on( "-d", "--dry-run", "Categorizes files, but does not take any actions on them." ) { [:dry_run] = true } opts.on( "-f", "--force", "--no-prompt", "Will take action without asking permissions; useful for automation." ) { [:prompt] = false } opts.on( "-a", "--archive-folder FOLDER", "The folder in which archives should be stored; defaults to <folder>/../<folder-name>-archives." ) { |path| [:archive_path] = path } opts.on( "--no-archive", "Don't perform archival; typically if the files you're pruning are already compressed." ) { [:archive] = false } opts.on( "--config", "Configure the retention policy for the specified folder." ) { [:configure] = true } opts.on_tail( "--version", "Displays version information." ) do [:did_work] = true print "Prune #{VERSION}, by Geoffrey Wiseman.\n" end opts.on_tail( "-?", "--help", "Shows quick help about using prune." ) do [:did_work] = true puts opts end end end |
.parse_and_run ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/prune/cli.rb', line 35 def self.parse_and_run = DEFAULT_OPTIONS.dup parser = make_parser begin parser.parse! if ARGV.size == 1 then if [:configure] then configurer = Configurer.new( ARGV.first, ) configurer.configure else Pruner.new( ).prune( ARGV.first ) end else print parser.help unless [:did_work] end rescue OptionParser::ParseError $stderr.print "Error: " + $!. + "\n" end end |