Class: Mono::Tool

Inherits:
Object
  • Object
show all
Defined in:
lib/mono/tool.rb

Class Method Summary collapse

Class Method Details

.main(args = ARGV) ⇒ Object



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
# File 'lib/mono/tool.rb', line 5

def self.main( args=ARGV )

  options = {}
  OptionParser.new do |parser|
    ## note:
    ##  you can add many/multiple modules
    ##  e.g. -r gitti -r mono etc.
    parser.on( '-r NAME', '--require NAME') do |name|
      options[:requires] ||= []
      options[:requires] << name
    end
    ## todo/fix:
    ##    add --verbose
    ##    add -d/--debug
  end.parse!( args )


  ## add check for auto-require (e.g. ./config.rb)
  if options[:requires]  ## use custom (auto-)requires
    options[:requires].each do |path|
      puts "[monofile] auto-require >#{path}<..."
      require( path )
    end
  else  ## use/try defaults
    config_path = "./config.rb"
    if File.exist?( config_path )
      puts "[monofile] auto-require (default) >#{config_path}<..."
      require( config_path )
    end
  end


 ## note: for now assume first argument is command
 cmd = if args.size == 0
         'status'   ## make status "default" command
       else
         args.shift   ## remove first (head) element
       end

 ## note: allow shortcut for commands
 case cmd.downcase
 when 'status', 'stati', 'stat', 'st', 's'
    Mono.status
 when 'sync', 'syn', 'sy',  ## note: allow aliases such as install, get & up too
      'get', 'g',
      'install', 'insta', 'inst', 'ins', 'i',
      'up', 'u'
    Mono.sync
 when 'fetch', 'f'
    Mono.fetch
 when 'env', 'e'
    Mono.env
 when 'backup', 'back', 'b'
    Mono.backup
 when 'run', 'r', 'exec'
    Mono.run( args )

 ##################
 ## for debugging / linting
 when 'walk'
    Mono.walk
 else
   puts "!! ERROR: unknown command >#{cmd}<"
   exit 1
 end

end