Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #21 from degica/document-kaiser
Browse files Browse the repository at this point in the history
Document kaiser
  • Loading branch information
davidsiaw authored Sep 19, 2019
2 parents fd2f935 + dd467e7 commit 4132d6d
Show file tree
Hide file tree
Showing 33 changed files with 1,230 additions and 733 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

# Specify your gem's dependencies in kaiser.gemspec
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
kaiser (0.3.1)
kaiser (0.4.0)
optimist

GEM
Expand Down Expand Up @@ -90,4 +90,4 @@ DEPENDENCIES
rspec (~> 3.0)

BUNDLED WITH
2.0.1
2.0.2
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'bundler/gem_tasks'
require 'rspec/core/rake_task'

Expand Down
1 change: 1 addition & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'bundler/setup'
require 'kaiser'
Expand Down
107 changes: 63 additions & 44 deletions exe/kaiser
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'optimist'
require 'fileutils'
Expand All @@ -9,55 +10,73 @@ require 'erb'

require 'kaiser'

SUB_COMMANDS = %w[
init
deinit
up
down
shutdown
db_load
db_save
db_reset
db_reset_hard
logs
attach
login
show
set
].freeze

opts = Optimist.options do
banner <<-BANNER
Kaiser v#{Kaiser::VERSION}
Subcommands:
#{SUB_COMMANDS.join ' '}
BANNER
opt :verbose, "Show Kaiser's debug output", short: '-v'
opt :quiet, 'Suppress all output', short: '-q'
end
sub_command_strings = Kaiser::SUB_COMMANDS.keys.map(&:to_s)

commands = SUB_COMMANDS & ARGV
cmd = commands.first
ARGV.shift
Kaiser::SUB_COMMANDS.each { |k, v| Kaiser::Cli.register(k, v) }

# It was difficult to allow global arguments like -v and -q to be typed both before and after cmds
# and still support `kaiser -h` for full help messages and `kaiser subcmd -h` for focused messages.
# Putting the global options in an array, using an Optimist::Parser and basically everything up to
# the 'end parser hacks' comment are all hacks to marry the above two behaviours.

global_opts = [
[:verbose, "Show Kaiser's debug output", short: '-v'],
[:quiet, 'Suppress all output', short: '-q']
]

parser = Optimist::Parser.new do
version "Kaiser v#{Kaiser::VERSION}"

banner <<~BANNER
#{version}
Kaiser is a tool to make development a lot easier by defining how an application starts using a \`Kaiserfile\` in the source code's root directory.
Prerequisites
=============
Install docker on your system and make sure the current user has all the rights required to spin up docker containers.
Usage
=====
For typical usage you'll want to do the following three commands.
Optimist.educate unless SUB_COMMANDS.include?(cmd)
\`\`\`
kaiser init ENV_NAME
kaiser up
kaiser attach
\`\`\`
out = Kaiser::Dotter.new
info_out = Kaiser::AfterDotter.new(dotter: out)
This will boot up your application in docker and bind mount your local source directory so you can start doing development. Happy coding!
if opts[:quiet]
out = File.open(File::NULL, 'w')
info_out = File.open(File::NULL, 'w')
elsif opts[:verbose]
out = $stderr
If any of these commands are giving you trouble, please run them with the \`-v\` flag set. They will show you what exactly is happening so you can debug.
Subcommands
===========
- #{Kaiser::SUB_COMMANDS.keys.join("\n- ")}
Type \`SUB_COMMAND -h\` for help with specific subcommands.
Global Parameters
=================
BANNER

global_opts.each { |o| opt *o }
end

cli = Kaiser::KaiserCli.new(
`pwd`.chomp,
debug_output: out,
info_output: info_out
)
cli.send(:"#{cmd}")
commands = sub_command_strings & ARGV

if commands.empty?
Optimist.with_standard_exception_handling parser do
raise Optimist::HelpNeeded
end
end

cmd = commands.first
## end parser hacks ##

Kaiser::Cli.run_command(:"#{cmd}", global_opts)

puts ''
1 change: 1 addition & 0 deletions kaiser.gemspec
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true

lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
Expand Down
37 changes: 36 additions & 1 deletion lib/kaiser.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,44 @@
# frozen_string_literal: true

require 'kaiser/version'
require 'kaiser/kaiserfile'
require 'kaiser/kaiser_cli'
require 'kaiser/cli'
require 'kaiser/after_dotter'
require 'kaiser/dotter'

require 'kaiser/config'

require 'kaiser/cmds/init'
require 'kaiser/cmds/deinit'
require 'kaiser/cmds/up'
require 'kaiser/cmds/down'
require 'kaiser/cmds/shutdown'
require 'kaiser/cmds/db_save'
require 'kaiser/cmds/db_load'
require 'kaiser/cmds/db_reset'
require 'kaiser/cmds/db_reset_hard'
require 'kaiser/cmds/logs'
require 'kaiser/cmds/attach'
require 'kaiser/cmds/login'
require 'kaiser/cmds/show'
require 'kaiser/cmds/set'

# Kaiser
module Kaiser
SUB_COMMANDS = {
init: Kaiser::Cmds::Init,
deinit: Kaiser::Cmds::Deinit,
up: Kaiser::Cmds::Up,
down: Kaiser::Cmds::Down,
shutdown: Kaiser::Cmds::Shutdown,
db_save: Kaiser::Cmds::DbSave,
db_load: Kaiser::Cmds::DbLoad,
db_reset: Kaiser::Cmds::DbReset,
db_reset_hard: Kaiser::Cmds::DbResetHard,
logs: Kaiser::Cmds::Logs,
attach: Kaiser::Cmds::Attach,
login: Kaiser::Cmds::Login,
show: Kaiser::Cmds::Show,
set: Kaiser::Cmds::Set
}.freeze
end
2 changes: 2 additions & 0 deletions lib/kaiser/after_dotter.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Kaiser
# Prints properly after a dotter prints
class AfterDotter
Expand Down
Loading

0 comments on commit 4132d6d

Please sign in to comment.