Class: Kwoon::CLI

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/kwoon/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


13
# File 'lib/kwoon/cli.rb', line 13

def self.exit_on_failure?; true; end

.source_rootObject



12
# File 'lib/kwoon/cli.rb', line 12

def self.source_root; File.expand_path(File.dirname(__FILE__)); end

Instance Method Details

#create(kata_name) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
# File 'lib/kwoon/cli.rb', line 18

def create(kata_name)
  @kata_name = kata_name
  @gemset = "kwoon_" + kata_name
  @ruby_version = options[:"ruby-version"]

  Bundler.with_clean_env do      
    puts "*** Creating kata directory"
    FileUtils.mkdir(kata_name)
    template "templates/autotest.tt",                 "#{kata_name}/.autotest"
    template "templates/gitignore.tt",                "#{kata_name}/.gitignore"
    template "templates/rspec.tt",                    "#{kata_name}/.rspec"
    template "templates/rvmrc.tt",                    "#{kata_name}/.rvmrc"
    template "templates/Gemfile.tt",                  "#{kata_name}/Gemfile"
    template "templates/autotest/discover.rb.tt",     "#{kata_name}/autotest/discover.rb"
    template "templates/autotest/kwoon_rspec2.rb.tt", "#{kata_name}/autotest/kwoon_rspec2.rb"
    template "templates/lib/kata_name.rb.tt",         "#{kata_name}/lib/#{kata_name}.rb"
    template "templates/spec/kata_name_spec.rb.tt",   "#{kata_name}/spec/#{kata_name}_spec.rb"
    template "templates/spec/spec_helper.rb.tt",      "#{kata_name}/spec/spec_helper.rb"
    puts
  
    puts "*** Creating kata gemset"
    system "rvm #{@ruby_version} gemset create #{@gemset}"
    puts
  
    Dir.chdir(kata_name) do
      puts "*** Installing & updating bundler"
      system "rvm #{@ruby_version}@#{@gemset} exec gem install bundler"
      system "rvm #{@ruby_version}@#{@gemset} exec gem update bundler"
      puts
    
      puts "*** Bundling kata gems"
      system "rvm #{@ruby_version}@#{@gemset} exec bundle"
      system "rvm #{@ruby_version}@#{@gemset} gem install #{options[:"kwoon-gem"]}"
      puts
    end
    
    puts "*** Now run the following commands:"
    puts "  cd #{kata_name}"
    puts "  kwoon git REPO_NAME"
    puts "  kwoon start USERNAME_1 USERNAME_2 ... USERNAME_N"
    puts "  autotest"
    puts
    puts "e.g."
    puts "  kwoon git [email protected]:account_name/repo.git"
    puts "  kwoon start fred wilma"
    puts
  end
end

#git(remote_repo_name = nil) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/kwoon/cli.rb', line 68

def git(remote_repo_name = nil)
  repo = Grit::Repo.init(".")

  if remote_repo_name
    puts "*** Configuring Git to point to #{remote_repo_name}"
    repo.config["push.default"] = "current"
    repo.remote_add("origin", remote_repo_name)
    puts
  else
    puts "*** Configuring Git without a remote repo"
    puts
  end
  
  repo.add(".")
  repo.commit_index("Initialise Kata")
end

#start(*usernames) ⇒ Object

Raises:

  • (Thor::Error)


86
87
88
89
90
91
92
# File 'lib/kwoon/cli.rb', line 86

def start(*usernames)
  raise Thor::Error.new("You must supply at least one username") if usernames.empty?
  repo = Grit::Repo.init(".")
  new_branch_name = "#{usernames.join("-")}-#{Time.new.strftime("%Y%m%d%H%M")}"
  repo.git.branch({}, new_branch_name, "master")
  repo.git.checkout({}, new_branch_name)
end