Skip to content

Commit f112d35

Browse files
committed
Refactor usage output
1 parent e2083f4 commit f112d35

File tree

2 files changed

+50
-14
lines changed

2 files changed

+50
-14
lines changed

bin/katapult

+37-13
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
# This script simplifies the usage of `katapult` by grouping relevant actions
44
# that the user else had to perform manually.
55

6-
usage = 'Usage: katapult new APP_NAME | fire [path/to/model] | version'
7-
86
require_relative '../lib/katapult/version'
97
require_relative '../lib/katapult/support/binary_util'
108
util = Katapult::BinaryUtil
@@ -35,6 +33,25 @@ is not supported by this version of katapult.
3533
Please switch to Ruby #{supported_ruby} and run again.
3634
MSG
3735

36+
# Prepare output ###############################################################
37+
38+
# This is also used as README heading
39+
version = <<-VERSION
40+
Katapult #{Katapult::VERSION}
41+
Generating a Rails #{Katapult::RAILS_VERSION} app on Ruby #{Katapult::RUBY_VERSION}.
42+
VERSION
43+
44+
usage = <<-USAGE
45+
Usage: katapult <command>
46+
47+
Commands:
48+
new APP_NAME Generate a configured Rails application
49+
fire [PATH] Transform application model into code
50+
Default path: lib/katapult/application_model.rb
51+
templates Copy templates to lib/templates/katapult
52+
version Print version
53+
USAGE
54+
3855

3956
case ARGV.shift
4057
when 'new'
@@ -74,18 +91,20 @@ when 'new'
7491
# Do not use `basics_command` as commit message, it contains the db password!
7592
util.git_commit 'rails generate katapult:basics', '--quiet'
7693

77-
util.pink <<-'INSTRUCTIONS'
94+
util.pink <<-INSTRUCTIONS
7895
Application initialization done.
7996
8097
Next steps:
81-
82-
- Run `bundle update` if you want to use the latest versions of all gems
83-
- Configure public/robots.txt
98+
- \`cd #{app_name}\`
99+
- Customize Katapult's template files in lib/templates/katapult
84100
- Model your application in lib/katapult/application_model.rb and transform it
85-
into code by running `katapult fire`
101+
into code by running \`katapult fire\`
102+
- Run \`bundle update\` if you want to use the latest versions of all gems
103+
- Configure public/robots.txt
86104
- Write a README
87105
INSTRUCTIONS
88106

107+
89108
when 'fire'
90109
app_model_path = ARGV.shift || 'lib/katapult/application_model.rb'
91110
transform_command = 'bin/rails generate katapult:transform ' + app_model_path
@@ -103,13 +122,18 @@ Now boot up your development server (e.g. with `rails server`) and try your
103122
kickstarted application in the browser!
104123
INSTRUCTIONS
105124

106-
when 'version', '-v'
107-
# This output is also used as README heading
108-
puts <<-VERSION
109-
Katapult #{Katapult::VERSION}
110-
Generating a Rails #{Katapult::RAILS_VERSION} app on Ruby #{Katapult::RUBY_VERSION}.
111-
VERSION
125+
126+
when 'templates'
127+
util.run 'bundle exec rails generate katapult:templates'
128+
util.pink 'Templates copied to lib/templates/katapult.'
129+
130+
131+
when 'version'
132+
puts version
133+
112134

113135
else
136+
puts version
137+
puts
114138
puts usage
115139
end

features/binary.feature

+13-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,17 @@ Feature: Katapult binary `katapult`
44

55
Scenario: Run without arguments
66
When I run `katapult`
7-
Then the output should contain "Usage: katapult new APP_NAME | fire [path/to/model] | version"
7+
Then the output should contain:
8+
"""
9+
Usage: katapult <command>
10+
11+
Commands:
12+
new APP_NAME Generate a configured Rails application
13+
fire [PATH] Transform application model into code
14+
Default path: lib/katapult/application_model.rb
15+
templates Copy templates to lib/templates/katapult
16+
version Print version
17+
"""
818

919

1020
Scenario: Print versions
@@ -50,10 +60,12 @@ Feature: Katapult binary `katapult`
5060
And the output should contain "Generating katapult basics"
5161

5262
And the output should contain "Application initialization done."
63+
And the output should contain "cd binary_test"
5364
And the output should contain "Model your application in lib/katapult/application_model.rb"
5465
And the output should contain "Configure public/robots.txt"
5566
And the output should contain "Write a README"
5667
And the output should contain "Run `bundle update`"
68+
And the output should contain "Customize Katapult's template files"
5769

5870
When I cd to "binary_test"
5971
Then the file "Gemfile" should contain "gem 'katapult'"

0 commit comments

Comments
 (0)