Class: Ecic::CLI

Inherits:
Command show all
Includes:
SourceFileAdder
Defined in:
lib/ecic/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SourceFileAdder

#add_src_file

Methods inherited from Command

dispatch

Class Method Details

.exit_on_failure?Boolean

Make sure to return non-zero value if an error is thrown.

Returns:

  • (Boolean)


23
24
25
# File 'lib/ecic/cli.rb', line 23

def self.exit_on_failure?
  true
end

.help(shell, subcommand = false) ⇒ Object



7
8
9
10
11
12
# File 'lib/ecic/cli.rb', line 7

def help(shell, subcommand = false)
  shell.say "Usage: ecic COMMAND [ARGS]"
  shell.say ""
  super
  shell.say "To get more help on a specific command, try 'ecic help [COMMAND]'"
end

.rootObject

TBA: Make a function that returns the root folder for the project



15
16
17
# File 'lib/ecic/cli.rb', line 15

def root
  File.expand_path("./tfj2")
end

Instance Method Details

#addfile(lib_name, *file_names) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/ecic/cli.rb', line 62

def addfile(lib_name, *file_names)
  begin
    root_dir = Project::root
    if root_dir.nil?
      shell.error "You must be within an ECIC project before calling this command"
      exit(1)
    end
    project = Project.new(root_dir)
    project.load_libraries

    unless project.has_library?(lib_name)
      if yes?("Library '#{lib_name}' does not exist. Create it? [y/n]:")
        generator = LibraryGenerator.new
        generator.destination_root = root_dir
        generator.library_name = lib_name
        generator.invoke_all
      else
        shell.error "Operation aborted!"
        exit(2)
      end
    end
    file_adder = FileAdder.new
    file_adder.library_name = lib_name
    file_adder.file_names = file_names
    file_adder.invoke_all

  rescue Exception => exc
    shell.error exc.message
    exit(3)
  end
  
end

#completion(*params) ⇒ Object



101
102
103
# File 'lib/ecic/cli.rb', line 101

def completion(*params)
  Completer.new(CLI, *params).run
end

#completion_scriptObject



110
111
112
# File 'lib/ecic/cli.rb', line 110

def completion_script
  Completer::Script.generate
end

#librariesObject



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/ecic/cli.rb', line 129

def libraries

  defaults = {
    "format"       => "text",
    "include_source_files" => false
  }
  opt = defaults.merge(options)
  
  root_dir = Project::root
  if root_dir.nil?
    shell.error "You must be within an ECIC project before calling this command" 
    exit(3)
  end
  project = Project.new(root_dir)
  project.load_libraries
  project.load_sources if opt['include_source_files']
  if opt['format'] == 'json'
    require 'json'
    say project.libraries.map{ |lib| lib.to_json(:include_source_files => opt['include_source_files']) }.join(",") 
  else
    say project.libraries.map{ |lib| lib.to_str(:include_source_files => opt['include_source_files']) }.join("\n") 
  end
end

#new(path) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/ecic/cli.rb', line 33

def new(path)
  path = File.expand_path(path)
  shell.say "Generating a new project in #{path}"
  generator = ProjectGenerator.new
  generator.destination_root = path
  generator.invoke_all
  
  shell.say "\nTo install the required packages in your project, please run:\n   cd #{path}; bundle install\n", Thor::Shell::Color::BOLD
  #TBA: invoke installation by eg. calling 'bundler install' from within the generated project folder    
#      Bundler.with_clean_env do
#        Dir.chdir(path) do
#          `bundle install`
#        end
#      end
end

#versionObject



118
119
120
# File 'lib/ecic/cli.rb', line 118

def version
  say "#{VERSION}"
end