Module: Dev::Executables::Commands::Feature

Included in:
Dev::Executable
Defined in:
lib/dev/executables/commands/feature.rb

Instance Method Summary collapse

Instance Method Details

#feature(command = nil, name = nil) ⇒ nil

Comandi per gestire l’apertura e la chiusura di una nuova feature.

Parameters:

  • command (String) (defaults to: nil)

    il comando da eseguire.

  • name (String) (defaults to: nil)

    il nome della feature.

Returns:

  • (nil)


13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/dev/executables/commands/feature.rb', line 13

def feature(command = nil, name = nil)
  raise Dev::Executable::ExecutionError.new "Wrong command syntax: "\
    "specify whether to open or close a feature. "\
    "Example: dev feature open my-new-feature" unless command.in? [ 'open', 'close' ]
  name = name.to_s.squish

  if @project.valid_app?
    case command
    when 'open' then feature_open(name)
    when 'close' then feature_close(name)
    end
  end
end

#feature_close(name) ⇒ nil

Chiude una feature esistente.

Parameters:

  • name (String)

    il nome della feature.

Returns:

  • (nil)


72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/dev/executables/commands/feature.rb', line 72

def feature_close(name)
  print "Preparing to close the feature for app "
  print @project.current_app.teal
  print " named "
  puts name.teal
  puts

  status = `git status`
  if status.include? "Changes not staged for commit:"
    raise Dev::Executable::ExecutionError.new "Your current branch has unstaged changes. Please "\
      "commit or stash them before closing the feature."
  end

  branches = `git branch -a`
  unless branches.include? ("feature/#{name}\n")
    raise Dev::Executable::ExecutionError.new "No feature named '#{name}' could be found "\
      "for this app's repository."
  end

  print "\tClosing.. "
  exec "git checkout develop"
  exec "git merge --no-ff feature/#{name}"
  git_output = exec "git push origin develop"
  if git_output.include?('fatal') or git_output.include?('rejected') or git_output.include?('error')
    print "X\n".red
    puts "\t\tSomething went wrong, take a look at the output from git:".indianred
    puts "\t\t#{git_output.split("\n").map(&:squish).join("\n\t\t")}".indianred
    puts
  else
    print "√\n".green
    puts "\t\tDone. Output from git:".cadetblue
    puts "\t\t#{git_output.split("\n").map(&:squish).join("\n\t\t")}".cadetblue
    puts
  end
end

#feature_open(name) ⇒ nil

Apre una nuova feature.

Parameters:

  • name (String)

    il nome della feature.

Returns:

  • (nil)


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
# File 'lib/dev/executables/commands/feature.rb', line 33

def feature_open(name)
  print "Preparing to open a new feature for app "
  print @project.current_app.teal
  print " named "
  puts name.teal
  puts

  branches = `git branch -a`
  unless branches.include? ("develop\n")
    print "\tCreating develop branch.."
    exec "git checkout -b develop"
    exec "git add ."
    exec "git commit -m \"Dev: automatically created 'develop' branch\""
    exec "git push -u origin develop"
    print "√\n".green
    puts
  end

  print "\tOpening.. "
  git_output = exec "git checkout -b feature/#{name} develop"
  if git_output.include?('fatal') or git_output.include?('rejected') or git_output.include?('error')
    print "X\n".red
    puts "\t\tSomething went wrong, take a look at the output from git:".indianred
    puts "\t\t#{git_output.split("\n").map(&:squish).join("\n\t\t")}".indianred
    puts
  else
    print "√\n".green
    puts "\t\tDone. Output from git:".cadetblue
    puts "\t\t#{git_output.split("\n").map(&:squish).join("\n\t\t")}".cadetblue
    puts
  end
end