Class: Dev::Executable

Overview

Classe per gestire l’esecuzione del comando dev.

Defined Under Namespace

Classes: ExecutionError

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Dev::Executables::Commands::Test

#test

Methods included from Dev::Executables::Commands::Push

#push

Methods included from Dev::Executables::Commands::Pull

#pull

Methods included from Dev::Executables::Commands::Release

#release, #release_close, #release_open

Methods included from Dev::Executables::Commands::Hotfix

#hotfix, #hotfix_close, #hotfix_open

Methods included from Dev::Executables::Commands::Feature

#feature, #feature_close, #feature_open

Methods included from Dev::Executables::Commands::Status

#status

Methods included from Dev::Executables::Commands::Version

#version

Constructor Details

#initialize(*argv) ⇒ Executable

Inizializza l’eseguibile, in base al comando passato.

Parameters:

  • argv (Array)

    gli argomenti del comando.



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
# File 'lib/dev/executable.rb', line 43

def initialize(*argv)
  begin
    if argv[0].present?
      if self.respond_to?(argv[0])
        # Carica i dati del progetto
        load_project
        # Lancia il comando passato
        if self.method(argv[0]).arity.abs > 0
          self.send(argv[0], *argv[1..-1])
        else
          self.send(argv[0])
        end
      else
        raise ExecutionError.new "Command '#{argv[0]}' is not supported. Run "\
          "'dev help' for a list of available commands."
      end
    else
      raise ExecutionError.new "Missing required parameters. Run 'dev help' "\
        "for a list of available commands."
    end
  rescue Dev::Executable::ExecutionError => e
    @error = e.message
    puts @error.red
  rescue StandardError => e
    @error = "#{e.class}: #{e.message}"
    @backtrace = e.backtrace.join("\n")
    puts @error.red
    puts @backtrace.red
  end
end

Instance Attribute Details

#backtraceString

Returns il backtrace dell’errore, se presente.

Returns:

  • (String)

    il backtrace dell’errore, se presente.



37
38
39
# File 'lib/dev/executable.rb', line 37

def backtrace
  @backtrace
end

#errorStandardError

Returns l’errore riscontrato, se presente.

Returns:

  • (StandardError)

    l’errore riscontrato, se presente.



35
36
37
# File 'lib/dev/executable.rb', line 35

def error
  @error
end

#projectDev::Executables::Project

Returns il progetto di riferimento.

Returns:

  • (Dev::Executables::Project)

    il progetto di riferimento.



33
34
35
# File 'lib/dev/executable.rb', line 33

def project
  @project
end

Instance Method Details

#exec(command, options = {}) ⇒ nil

Esegue un comando e cattura l’output ritornandolo come risultato di questo metodo. Si può passare l’opzione flush per stampare subito l’output come se non fosse stato catturato.

Parameters:

  • command (String)

    il comando da eseguire.

  • options (Hash) (defaults to: {})

    le opzioni.

Returns:

  • (nil)


109
110
111
112
113
114
115
116
117
# File 'lib/dev/executable.rb', line 109

def exec(command, options = {})
  out, err, status = Open3.capture3(command)
  command_output = [ out.presence, err.presence ].compact.join("\n")
  if options[:flush] == true
    puts command_output
  else
    command_output
  end
end

#helpnil

Stampa i comandi possibili.

Returns:

  • (nil)


123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/dev/executable.rb', line 123

def help
  puts
  print "Dev".green
  print " - available commands:\n"
  puts
  
  print "\tversion\t\t".limegreen 
    print "Prints current version.\n"
    puts

  print "\tfeature\t\t".limegreen
    print "Opens or closes a feature for the current app.\n"
    print "\t\t\tWarning: the app is determined from the current working directory!\n"
    print "\t\t\tExample: "
    print "dev feature open my-new-feature".springgreen
    print " (opens a new feature for the current app)"
    print ".\n"
    print "\t\t\tExample: "
    print "dev feature close my-new-feature".springgreen
    print " (closes a developed new feature for the current app)"
    print ".\n"
    puts

  print "\thotfix\t\t".limegreen
    print "Opens or closes a hotfix for the current app.\n"
    print "\t\t\tWarning: the app is determined from the current working directory!\n"
    print "\t\t\tExample: "
    print "dev hotfix open 0.2.1".springgreen
    print " (opens a new hotfix for the current app)"
    print ".\n"
    print "\t\t\tExample: "
    print "dev hotfix close 0.2.1".springgreen
    print " (closes a developed new hotfix for the current app)"
    print ".\n"
    puts

  print "\trelease\t\t".limegreen
    print "Opens or closes a release for the current app.\n"
    print "\t\t\tWarning: the app is determined from the current working directory!\n"
    print "\t\t\tExample: "
    print "dev release open 0.2.0".springgreen
    print " (opens a new release for the current app)"
    print ".\n"
    print "\t\t\tExample: "
    print "dev release close 0.2.0".springgreen
    print " (closes a developed new release for the current app)"
    print ".\n"
    puts

  print "\tpull\t\t".limegreen
    print "Pulls specified app's git repository, or pulls all apps if none are specified.\n"
    print "\t\t\tWarning: the pulled branch is the one the app is currently on!\n"
    print "\t\t\tExample: "
    print "dev pull [myapp]".springgreen
    print ".\n"
    puts

  print "\tpush\t\t".limegreen
    print "Commits and pushes the specified app.\n"
    print "\t\t\tWarning: the pushed branch is the one the app is currently on!\n"
    print "\t\t\tExample: "
    print "dev push myapp \"commit message\"".springgreen
    print ".\n"
    puts

  print "\ttest\t\t".limegreen
    print "Runs the app's test suite. Tests must be written with rspec.\n"
    print "\t\t\tIt is possibile to specify which app's test suite to run.\n"
    print "\t\t\tIf nothing is specified, all main app's test suites are run.\n"
    print "\t\t\tExample: "
    print "dev test mymainapp myengine".springgreen
    print " (runs tests for 'mymainapp' and 'myengine')"
    print ".\n"
    print "\t\t\tExample: "
    print "dev test".springgreen
    print " (runs tests for all main apps and engines within this project)"
    print ".\n"
    puts
end

#load_projectnil

Carica i dati del progetto prendendoli dal file di configurazione del file ‘dev.yml’.

Returns:

  • (nil)


79
80
81
82
83
84
# File 'lib/dev/executable.rb', line 79

def load_project
  config_file = Dir.glob("#{Dir.pwd}/**/dev.yml").first
  raise ExecutionError.new "No valid configuration files found. Searched for a file named 'dev.yml' "\
    "in folder #{Dir.pwd} and all its subdirectories." if config_file.nil?
  @project = Dev::Project.new(config_file)
end

#valid_env?Boolean

Determina de l’env è valido.

Returns:

  • (Boolean)

    se l’env è fra quelli validi.



90
91
92
93
94
95
96
97
# File 'lib/dev/executable.rb', line 90

def valid_env?
  unless @env.in? [ :production, :staging ]
    raise ExecutionError.new "The environment '#{@env}' is not valid. "\
      "Valid environments are 'production' or 'staging'."
  else
    true
  end
end