Class: Ecic::CLI
- Includes:
- SourceFileAdder
- Defined in:
- lib/ecic/cli.rb
Class Method Summary collapse
-
.exit_on_failure? ⇒ Boolean
Make sure to return non-zero value if an error is thrown.
- .help(shell, subcommand = false) ⇒ Object
-
.root ⇒ Object
TBA: Make a function that returns the root folder for the project.
Instance Method Summary collapse
- #addfile(lib_name, *file_names) ⇒ Object
- #completion(*params) ⇒ Object
- #completion_script ⇒ Object
- #libraries ⇒ Object
- #new(path) ⇒ Object
- #version ⇒ Object
Methods included from SourceFileAdder
Methods inherited from Command
Class Method Details
.exit_on_failure? ⇒ Boolean
Make sure to return non-zero value if an error is thrown.
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 |
.root ⇒ Object
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.("./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. 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_script ⇒ Object
110 111 112 |
# File 'lib/ecic/cli.rb', line 110 def completion_script Completer::Script.generate end |
#libraries ⇒ Object
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() 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.(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 |
#version ⇒ Object
118 119 120 |
# File 'lib/ecic/cli.rb', line 118 def version say "#{VERSION}" end |