Class: CyberMots::ILC::Commandes

Inherits:
Object
  • Object
show all
Includes:
TTY::Option
Defined in:
biliothèque/cybermots/ilc/commandes.rb

Overview

Commande racine, aiguille vers les autres commandes

Instance Method Summary collapse

Instance Method Details

#lanceObject



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
# File 'biliothèque/cybermots/ilc/commandes.rb', line 34

def lance
  if params.errors.any?
    puts params.errors.summary
  else
    cmd, args = case ARGV[0]
                when 'maj'
                  [Maj.new, ARGV[1..]]
                when 'liste'
                  [Liste.new, ARGV[1..]]
                when 'cherche'
                  [Cherche.new, ARGV[1..]]
                end

    if cmd.nil?
      if params[:version]
        puts "CyberMots version #{CyberMots::VERSION}"
      else
        h = help(width: ILC::LARGEUR_TERM) do |sections|
          sections.add_after :description, :commandes, <<~COMMANDES.chomp

            Commandes :
              #{Cherche.command.first} : #{Cherche.desc.first.first}
              #{Liste.command.first}   : #{Liste.desc.first.first}
              #{Maj.command.first}     : #{Maj.desc.first.first}
          COMMANDES
        end
        print h
      end
    else
      cmd.parse args
      cmd.lance
    end
  end
end