Class: TDiary::CLI
- Includes:
- Thor::Actions
- Defined in:
- lib/tdiary/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
- #assets_copy ⇒ Object
- #htpasswd ⇒ Object
- #new(name) ⇒ Object
- #server ⇒ Object
- #test ⇒ Object
- #update ⇒ Object
- #version ⇒ Object
Class Method Details
.source_root ⇒ Object
10 11 12 |
# File 'lib/tdiary/cli.rb', line 10 def self.source_root File.('../../..', __FILE__) end |
Instance Method Details
#assets_copy ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/tdiary/cli.rb', line 60 def assets_copy require 'tdiary' assets_path = File.join(TDiary.server_root, 'public/assets') TDiary::Application.config.assets_paths.each do |path| Dir.glob(File.join(path, '*')).each do |entity| if File.directory?(entity) directory entity, File.join(assets_path, File.basename(entity)) else copy_file entity, File.join(assets_path, File.basename(entity)) end end end end |
#htpasswd ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/tdiary/cli.rb', line 135 def htpasswd require 'webrick/httpauth/htpasswd' say "Input your username/password" print 'Username: ' ARGV.replace([]) username = gets().chop print 'New password: ' system "stty -echo" password = $stdin.gets.chop puts print 'Re-type new password: ' password2 = $stdin.gets.chop puts system "stty echo" if password != password2 raise StandardError, 'password verification error' end htpasswd = WEBrick::HTTPAuth::Htpasswd.new('.htpasswd') htpasswd.set_passwd(nil, username, password) htpasswd.flush end |
#new(name) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/tdiary/cli.rb', line 17 def new(name) target = File.join(Dir.pwd, name) deploy(target) copy_file('tdiary.conf.beginner', File.join(target, 'tdiary.conf')) template('misc/templates/Gemfile.local.erb', File.join(target, 'Gemfile.local')) unless [:'skip-bundle'] Bundler.with_clean_env do inside(target) do run('bundle install --without test development') run('bundle exec tdiary htpasswd') end end else say "run `bundle install && bundle exec tdiary htpasswd` manually", :red end say 'install finished', :green say "run `tdiary server` in #{name} directory to start server", :green end |
#server ⇒ Object
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/tdiary/cli.rb', line 101 def server require 'tdiary' require 'tdiary/environment' if [:cgi] opts = { :daemon => ENV['DAEMON'], :bind => [:bind], :port => [:port], :logger => $stderr, :access_log => [:log] ? File.open([:log], 'a') : $stderr } TDiary::Server.run( opts ) elsif # --rack option # Rack::Server reads ARGV as :config, so delete it require 'webrick' ARGV.shift opts = { :environment => ENV['RACK_ENV'] || "development", :daemonize => false, :Host => [:bind], :Port => [:port], :pid => File.("tdiary.pid"), :config => File.("config.ru") } if [:log] opts[:AccessLog] = [[File.open([:log], 'a'), WEBrick::AccessLog::CLF]] end ::Rack::Server.start( opts ) end end |
#test ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/tdiary/cli.rb', line 75 def test target = File.join(Dir.pwd, 'tmp/test') deploy(target) append_to_file(File.join(target, 'Gemfile'), "path '#{CLI::source_root}'") directory('spec', File.join(target, 'spec')) directory('test', File.join(target, 'test')) Bundler.with_clean_env do inside(target) do run('bundle install') run('bundle exec rake spec') end end end |
#update ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/tdiary/cli.rb', line 40 def update target = Dir.pwd unless in_tdiary_dir?(target) say "please run update command in your tdiary directory", :red return 1 end deploy(target) unless [:'skip-bundle'] Bundler.with_clean_env do inside(target) do run('bundle install --without test development') end end end say 'update finished', :green end |