class Dev::Executable

Classe per gestire l'esecuzione del comando dev.

Attributes

backtrace[RW]

@return [String] il backtrace dell'errore, se presente.

error[RW]

@return [StandardError] l'errore riscontrato, se presente.

project[RW]

@return [Dev::Executables::Project] il progetto di riferimento.

Public Class Methods

new(*argv) click to toggle source

Inizializza l'eseguibile, in base al comando passato.

@param [Array] argv gli argomenti del comando.

# 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

Public Instance Methods

exec(command, options = {}) click to toggle source

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.

@param [String] command il comando da eseguire. @param [Hash] options le opzioni.

@return [nil]

# 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
help() click to toggle source

Stampa i comandi possibili.

@return [nil]

# 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_project() click to toggle source

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

@return [nil]

# 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?() click to toggle source

Determina de l'env è valido.

@return [Boolean] se l'env è fra quelli validi.

# 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