Class: MainApp

Inherits:
Object
  • Object
show all
Defined in:
lib/gito.rb

Instance Method Summary collapse

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
  @options = {}
  @options[:app_path] = nil
  @options[:should_edit] = false
  @options[:should_open] = false
  @options[:dryrun] = false
  @options[:editor] = nil
  @options[:setting_up] = false
  @options[:is_temp] = false
  @options[:shell_copy] = false

  # Parse Options
  create_options_parser(arguments)
end

Instance Method Details

#callObject



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 @options[:setting_up]
    if @options[:editor].nil?
        puts 'New new editor can\'t be empty'.red
      else
        update_configuration
        puts 'Updated the editor to: ' + @options[: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(@options[:is_temp], @options[:shell_copy])

  # Open in editor
  if @options[:should_edit]
    project.open_editor @options[:editor]
  end

  # Open in Finder
  if @options[:should_open]
    project.open_folder
  end

  # Install dependencies
  unless @options[: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 create_options_parser(args)
  args.options do |opts|
    opts.banner = '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|
      @options[:editor] = editor.nil? ? nil : editor
      @options[:setting_up] = true
    end

    opts.on('-e', '--edit', 'Open the project on an editor') do |editor|
      @options[:should_edit] = true
    end

    opts.on('-o', '--open', 'Open the project on Finder') do |edit|
      @options[:should_open] = true
    end

    opts.on('-d', '--dryrun', 'Doesn\'t install the dependencies') do |dryrun|
      @options[:dryrun] = true
    end

    opts.on('-t', '--temp', 'Clones the project into a temporary folder') do |is_temp|
      @options[:is_temp] = true
    end

    opts.on('-c', '--shell-copy', 'Only makes a shell copy of the repository') do |is_temp|
      @options[: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_configurationObject



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 @options[:editor].nil?
    @options[:editor] = app_config[:editor]
  else
    config_manager.write_editor @options[:editor]
  end
end