Class: MainApp
- Inherits:
-
Object
- Object
- MainApp
- Defined in:
- lib/gito.rb
Instance Method Summary collapse
- #call ⇒ Object
- #create_options_parser(args) ⇒ Object
-
#initialize(arguments) ⇒ MainApp
constructor
A new instance of MainApp.
- #update_configuration ⇒ Object
Constructor Details
#initialize(arguments) ⇒ MainApp
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/gito.rb', line 13 def initialize(arguments) @url = %w(-h --help -v --version -s --set-editor).include?(arguments.first) ? nil : arguments.shift # defaults = {} [:app_path] = nil [:should_edit] = false [:should_open] = false [:dryrun] = false [:editor] = nil [:setting_up] = false [:is_temp] = false [:shell_copy] = false # Parse Options (arguments) end |
Instance Method Details
#call ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/gito.rb', line 88 def call if [:setting_up] if [:editor].nil? puts 'New new editor can\'t be empty'.red else update_configuration puts 'Updated the editor to: ' + [:editor].yellow end exit end if @url.nil? puts 'You need to insert a valid GIT URL/folder' exit end # handle the configuration update_configuration project = Project.new(@url) # Clone the repository project.clone([:is_temp], [:shell_copy]) # Open in editor if [:should_edit] project.open_editor [:editor] end # Open in Finder if [:should_open] project.open_folder end # Install dependencies unless [:dryrun] project.install_dependencies end puts "\nš Finished".yellow # Change to directory project.change_directory end |
#create_options_parser(args) ⇒ Object
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 73 74 75 |
# File 'lib/gito.rb', line 32 def (args) args. do |opts| opts. = 'Usage: gito GIT_URL [OPTIONS]' opts.separator '' opts.separator 'Options' opts.on('-s EDITOR', '--set-editor EDITOR', 'Set a custom editor to open the project (e.g. "atom", "subl", "vim", etc.') do |editor| [:editor] = editor.nil? ? nil : editor [:setting_up] = true end opts.on('-e', '--edit', 'Open the project on an editor') do |editor| [:should_edit] = true end opts.on('-o', '--open', 'Open the project on Finder') do |edit| [:should_open] = true end opts.on('-d', '--dryrun', 'Doesn\'t install the dependencies') do |dryrun| [:dryrun] = true end opts.on('-t', '--temp', 'Clones the project into a temporary folder') do |is_temp| [:is_temp] = true end opts.on('-c', '--shell-copy', 'Only makes a shell copy of the repository') do |is_temp| [:shell_copy] = true end opts.on('-h', '--help', 'Displays help') do puts opts.help exit end opts.on('-v', '--version', 'Displays the version') do puts Gito::VERSION exit end opts.parse! end end |
#update_configuration ⇒ Object
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/gito.rb', line 77 def update_configuration config_manager = ConfigManager.new app_config = config_manager.get if [:editor].nil? [:editor] = app_config[:editor] else config_manager.write_editor [:editor] end end |