Class: TDiary::CLI
- Inherits:
-
Thor
- Object
- Thor
- 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
9 10 11 |
# File 'lib/tdiary/cli.rb', line 9 def self.source_root File.('../../..', __FILE__) end |
Instance Method Details
#assets_copy ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/tdiary/cli.rb', line 59 def assets_copy require 'tdiary' assets_path = File.join(TDiary.server_root, 'public/assets') TDiary::Application.new.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
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/tdiary/cli.rb', line 134 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
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/tdiary/cli.rb', line 16 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
100 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 |
# File 'lib/tdiary/cli.rb', line 100 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
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/tdiary/cli.rb', line 74 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
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/tdiary/cli.rb', line 39 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 |