Method: Mono::Tool.main

Defined in:
lib/mono/tool.rb

.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
72
# 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'
    status
 when 'sync', 'syn', 'sy',  ## note: allow aliases such as install, get & up too

      'get', 'g',
      'install', 'insta', 'inst', 'ins', 'i',
      'up', 'u'
    sync
 when 'fetch', 'f'
    fetch
 when 'env', 'e'
    env
 when 'backup', 'back', 'b'
    backup
 when 'run', 'r', 'exec'
    run( args )


 ##################

 ## for debugging / linting

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

end