cli-template 3.1.0 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/README.md +44 -5
  4. data/lib/cli-template/helpers.rb +3 -0
  5. data/lib/cli-template/sequence.rb +5 -4
  6. data/lib/cli-template/version.rb +1 -1
  7. data/lib/templates/colon_namespaces/%project_name%.gemspec.tt +30 -0
  8. data/lib/templates/colon_namespaces/.gitignore +16 -0
  9. data/lib/templates/colon_namespaces/.rspec +2 -0
  10. data/lib/templates/colon_namespaces/CHANGELOG.md +7 -0
  11. data/lib/templates/colon_namespaces/Gemfile.tt +6 -0
  12. data/lib/templates/colon_namespaces/Guardfile +19 -0
  13. data/lib/templates/colon_namespaces/LICENSE.txt.tt +22 -0
  14. data/lib/templates/colon_namespaces/README.md.tt +47 -0
  15. data/lib/templates/colon_namespaces/Rakefile +6 -0
  16. data/lib/templates/colon_namespaces/exe/%project_name%.tt +14 -0
  17. data/lib/templates/colon_namespaces/lib/%project_name%.rb.tt +12 -0
  18. data/lib/templates/colon_namespaces/lib/%underscored_name%/cli.rb.tt +166 -0
  19. data/lib/templates/colon_namespaces/lib/%underscored_name%/command.rb.tt +186 -0
  20. data/lib/templates/colon_namespaces/lib/%underscored_name%/completer.rb.tt +145 -0
  21. data/lib/templates/colon_namespaces/lib/%underscored_name%/completer/script.rb.tt +6 -0
  22. data/lib/templates/colon_namespaces/lib/%underscored_name%/completer/script.sh.tt +16 -0
  23. data/lib/templates/{default → colon_namespaces}/lib/%underscored_name%/completions.rb.tt +0 -0
  24. data/lib/templates/colon_namespaces/lib/%underscored_name%/help.rb.tt +9 -0
  25. data/lib/templates/{default → colon_namespaces}/lib/%underscored_name%/help/completions.md.tt +0 -0
  26. data/lib/templates/{default → colon_namespaces}/lib/%underscored_name%/help/completions/script.md.tt +0 -0
  27. data/lib/templates/colon_namespaces/lib/%underscored_name%/help/hello.md.tt +5 -0
  28. data/lib/templates/colon_namespaces/lib/%underscored_name%/help/main.md.tt +5 -0
  29. data/lib/templates/colon_namespaces/lib/%underscored_name%/help/sub/goodbye.md.tt +5 -0
  30. data/lib/templates/{default → colon_namespaces}/lib/%underscored_name%/main.rb.tt +0 -0
  31. data/lib/templates/{default → colon_namespaces}/lib/%underscored_name%/rake_command.rb.tt +0 -0
  32. data/lib/templates/colon_namespaces/lib/%underscored_name%/sub.rb.tt +12 -0
  33. data/lib/templates/colon_namespaces/lib/%underscored_name%/version.rb.tt +3 -0
  34. data/lib/templates/colon_namespaces/spec/lib/cli_spec.rb.tt +37 -0
  35. data/lib/templates/colon_namespaces/spec/spec_helper.rb.tt +29 -0
  36. data/lib/templates/default/.gitignore +1 -1
  37. data/lib/templates/default/Gemfile.lock.tt +64 -0
  38. data/lib/templates/default/LICENSE.txt +1 -1
  39. data/lib/templates/default/lib/%project_name%.rb.tt +1 -2
  40. data/lib/templates/default/lib/%underscored_name%/cli.rb.tt +24 -165
  41. data/lib/templates/default/lib/%underscored_name%/command.rb.tt +21 -151
  42. data/lib/templates/default/lib/%underscored_name%/completer.rb.tt +58 -57
  43. data/lib/templates/default/lib/%underscored_name%/completer/script.sh.tt +4 -10
  44. data/lib/templates/default/lib/%underscored_name%/completion.rb.tt +15 -0
  45. data/lib/templates/default/lib/%underscored_name%/help/completion.md.tt +22 -0
  46. data/lib/templates/default/lib/%underscored_name%/help/completion_script.md.tt +3 -0
  47. data/lib/templates/default/spec/lib/cli_spec.rb.tt +18 -17
  48. data/lib/templates/default/spec/spec_helper.rb.tt +2 -2
  49. data/spec/lib/cli_spec.rb +49 -38
  50. metadata +35 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5cec11731996364ad6e192824c457ce0800423eb72ac4782bdf72bfb8fd32155
4
- data.tar.gz: 8a5748d23604d64f35a5ecc98d6fbf1610cde7ac848c8480be36629d4dd3d5b3
3
+ metadata.gz: ebf247e389131d796f851f63170b372317765995899ac852510ae2e08d6807b7
4
+ data.tar.gz: c6c607ea96e976aaa38791f1d4a16a3630f6ae2ef3a548093f6305cb69a9fba1
5
5
  SHA512:
6
- metadata.gz: 1ad85e072ea3ca0c17b63c568034d0d962b3d12baa8c848efa585c6d21aa3bd8c49c2f6305ca73fd63002fbafd1a7c600037e0952419336ffcf2420562ffcc36
7
- data.tar.gz: 33a433e8b3b050a39f9fd11563d6c12843e7979d18a0f0401a5d1b61813e6dd419cb6b0f6fd57a1d18ed1328c045f2ded87968a061915787940211d6e9fdcaa4
6
+ metadata.gz: ba5b206f2bfd776d993e00bc78ff39b539a70505082992af8935985ae76b6b67d17fd92913c9a997f460bd6578562b7b87c78b3ccaa5a031492842f5afe095ac
7
+ data.tar.gz: e23520496b7e64d9c6563c9dd9a5b57ab921f5c069ea25a6c314047f4084785e96dfa6a81aa66401f8443414f84fbf79f56ec8f6ad6e516d8142be2033944eb3
@@ -3,6 +3,10 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
5
 
6
+ ## [3.2.0]
7
+ - Merge pull request #2 from tongueroo/basic: the deafult template is a basic Thor CLI instead of the colon_namespaces one.
8
+ - cache eager_load call and handle Thor::InvocationError
9
+
6
10
  ## [3.1.0]
7
11
  - Merge pull request #1 from tongueroo/completions: support for TAB auto-completion
8
12
  - add completions command to starter project
data/README.md CHANGED
@@ -3,17 +3,22 @@
3
3
  [![CircleCI](https://circleci.com/gh/tongueroo/cli-template.svg?style=svg)](https://circleci.com/gh/tongueroo/cli-template)
4
4
  [![Maintainability](https://api.codeclimate.com/v1/badges/c6c4f26aaafccab10baf/maintainability)](https://codeclimate.com/github/tongueroo/cli-template/maintainability)
5
5
 
6
- `cli-template` is a generator tool that builds a starter CLI project based on [Thor](http://whatisthor.com/). It is the successor tool to [thor_template](https://github.com/tongueroo/thor_template), which is also a tool that generates CLI projects. The main difference is `cli-template` uses colons for namespaced commands. The usage section demonstrates a namespaced command below.
6
+ `cli-template` is a generator tool that builds a starter CLI project based on [Thor](http://whatisthor.com/). It is the successor tool to [thor_template](https://github.com/tongueroo/thor_template), which is also a tool that generates CLI projects.
7
7
 
8
8
  The predecessor tool is covered in this original blog post, [Build Thor CLI Project in Under a Second](https://blog.boltops.com/2017/09/14/build-thor-cli-project-in-under-a-second). It covers usage and also contains a video demo. An updated blog post will eventually be made, for now, refer to the original blog post.
9
9
 
10
+ The generated CLI project comes with:
11
+
12
+ * example passing specs
13
+ * auto-completion
14
+
10
15
  ## Usage
11
16
 
12
17
  ```sh
13
18
  cli-template new mycli
14
19
  cd mycli
15
20
  exe/mycli hello world
16
- exe/mycli sub:goodbye world
21
+ exe/mycli sub:goodbye world # namespaced command with colons
17
22
  ```
18
23
 
19
24
  The above generated a starter CLI project called `mycli` with a working hello command. The created project also has starter specs for you 😁
@@ -45,13 +50,47 @@ rake release
45
50
 
46
51
  When installed as a gem, you no longer have to prepend exe in front of the command. For example, `exe/mycli` becomes the `mycli` command.
47
52
 
53
+ ## Different starter templates
54
+
55
+ There are 2 different templates that the tool generates from:
56
+
57
+ 1. basic thor project: A standard CLI tool based on basic usage of Thor.
58
+ 2. colon namespaced project: The generated CLI project still uses Thor but it does some manipulation in order to allow defining namespaced methods with colons instead of spaces. Example: `mycli sub:command` vs `mycli sub command`.
59
+
60
+ To use the different templates:
61
+
62
+ ```
63
+ TEMPLATE=colon_namespaces cli-template new mycli
64
+ TEMPLATE=default cli-template new mycli
65
+ cli-template new mycli # same as TEMPLATE=default
66
+ ```
67
+
48
68
  ## Auto Completion
49
69
 
50
- The generated CLI tool supports TAB auto-completion. To enable auto, you can add this to your `~/.bashrc` or `~/.profile`:
70
+ There is support for TAB completion in the newly generated CLI project for the default template. To enable auto completion, add this to `~/.bashrc` or `~/.profile`:
71
+
72
+ eval $(mycli completion_script)
73
+
74
+ Remember to re-load the shell. Note, the auto completion will only work if the cli command is avaialble in your PATH. You can do this by installing the gem. You can also create a wrapper bash script that calls to your development cli command like so:
75
+
76
+ ```
77
+ cat > /usr/local/bin/mycli << 'EOL'
78
+ #!/bin/bash
79
+ exec ~/src/mycli/exe/mycli "$@"
80
+ EOL
81
+ chmod a+x /usr/local/bin/mycli
82
+ ```
83
+
84
+ ### Experimental Auto Completion Support for colon_namespaces Template
85
+
86
+ The auto-completion for the colon_namespaces template CLI project is experimental. Ran into a few issues:
51
87
 
52
- eval $(mycli completions:script)
88
+ 1. Slow as to make auto-completion useless. This because the generated CLI invokes autoloading when it detects the methods for the completion words. Ideas on speeding this would be appreciated! Right now it takes about 1 second.
89
+ 2. Does not work with colons currently. Will have to look into this post [Bash Command-Line Tab Completion Colon Character
90
+ ](https://stackoverflow.com/questions/25362968/bash-command-line-tab-completion-colon-character).
91
+ 3. Does not work with the last two characters are `--`.
53
92
 
54
- Remember to re-load your shell. Note, the auto completion will only work once you tool is installed and it's binary is avaialble in your PATH.
93
+ Suggestions to are appreciated!
55
94
 
56
95
  ## Installation
57
96
 
@@ -9,4 +9,7 @@ module CliTemplate::Helpers
9
9
  def underscored_name
10
10
  project_name.underscore
11
11
  end
12
+
13
+ # project_name is also available from new.rb:
14
+ # argument :project_name
12
15
  end
@@ -9,7 +9,8 @@ class CliTemplate::Sequence < Thor::Group
9
9
  include CliTemplate::Helpers
10
10
 
11
11
  def self.source_root
12
- File.expand_path("../../templates/default", __FILE__)
12
+ template = ENV['TEMPLATE'] || 'default'
13
+ File.expand_path("../../templates/#{template}", __FILE__)
13
14
  end
14
15
 
15
16
  private
@@ -27,9 +28,9 @@ private
27
28
  end
28
29
 
29
30
  def confirm_cli_project
30
- jets_project = File.exist?("#{project_name}/config/application.rb")
31
- unless jets_project
32
- puts "It does not look like the repo #{options[:repo]} is a jets project. Maybe double check that it is? Exited.".colorize(:red)
31
+ cli_project = File.exist?("#{project_name}/config/application.rb")
32
+ unless cli_project
33
+ puts "It does not look like the repo #{options[:repo]} is a cli project. Maybe double check that it is? Exited.".colorize(:red)
33
34
  exit 1
34
35
  end
35
36
  end
@@ -1,3 +1,3 @@
1
1
  module CliTemplate
2
- VERSION = "3.1.0"
2
+ VERSION = "3.2.0"
3
3
  end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "<%= underscored_name %>/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "<%= project_name %>"
8
+ spec.version = <%= project_class_name %>::VERSION
9
+ spec.authors = ["Tung Nguyen"]
10
+ spec.email = ["tongueroo@gmail.com"]
11
+ spec.description = "Generated with cli-template tool. Please write a gem description"
12
+ spec.summary = "Generated with cli-template tool. Please write a gem summary"
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "thor"
23
+ spec.add_dependency "colorize"
24
+ spec.add_dependency "rake"
25
+ spec.add_dependency "activesupport"
26
+
27
+ spec.add_development_dependency "bundler"
28
+ spec.add_development_dependency "byebug"
29
+ spec.add_development_dependency "rspec"
30
+ end
@@ -0,0 +1,16 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ _yardoc
7
+ coverage
8
+ doc/
9
+ InstalledFiles
10
+ lib/bundler/man
11
+ pkg
12
+ rdoc
13
+ spec/reports
14
+ test/tmp
15
+ test/version_tmp
16
+ tmp
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
@@ -0,0 +1,7 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ This project *tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
+
6
+ ## [0.1.0]
7
+ - Initial release.
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem dependencies in <%= project_name %>.gemspec
4
+ gemspec
5
+
6
+ gem "codeclimate-test-reporter", group: :test, require: nil
@@ -0,0 +1,19 @@
1
+ guard "bundler", cmd: "bundle" do
2
+ watch("Gemfile")
3
+ watch(/^.+\.gemspec/)
4
+ end
5
+
6
+ guard :rspec, cmd: "bundle exec rspec" do
7
+ require "guard/rspec/dsl"
8
+ dsl = Guard::RSpec::Dsl.new(self)
9
+
10
+ # RSpec files
11
+ rspec = dsl.rspec
12
+ watch(rspec.spec_helper) { rspec.spec_dir }
13
+ watch(rspec.spec_support) { rspec.spec_dir }
14
+ watch(rspec.spec_files)
15
+
16
+ # Ruby files
17
+ ruby = dsl.ruby
18
+ dsl.watch_spec_files_for(ruby.lib_files)
19
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) <%= Time.now.strftime("%Y") %> Tung Nguyen
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,47 @@
1
+ # <%= project_class_name %>
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/GEMNAME.png)](http://badge.fury.io/rb/GEMNAME)
4
+ [![CircleCI](https://circleci.com/gh/USER/REPO.svg?style=svg)](https://circleci.com/gh/USER/REPO)
5
+ [![Dependency Status](https://gemnasium.com/USER/REPO.png)](https://gemnasium.com/USER/REPO)
6
+ [![Coverage Status](https://coveralls.io/repos/USER/REPO/badge.png)](https://coveralls.io/r/USER/REPO)
7
+ [![Join the chat at https://gitter.im/USER/REPO](https://badges.gitter.im/USER/REPO.svg)](https://gitter.im/USER/REPO?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
8
+ [![Support](https://img.shields.io/badge/get-support-blue.svg)](https://boltops.com?utm_source=badge&utm_medium=badge&utm_campaign=cli-template)
9
+
10
+ TODO: Write a gem description
11
+
12
+ ## Usage
13
+
14
+ ```sh
15
+ <%= project_name %> hello yourname
16
+ <%= project_name %> sub:goodbye yourname
17
+ ```
18
+
19
+ The CLI tool also detects and tasks in the current folder's Rakefile and delegate to those tasks.
20
+
21
+ ## Installation
22
+
23
+ Add this line to your application's Gemfile:
24
+
25
+ ```sh
26
+ gem "<%= project_name %>"
27
+ ```
28
+
29
+ And then execute:
30
+
31
+ ```sh
32
+ bundle
33
+ ```
34
+
35
+ Or install it yourself as:
36
+
37
+ ```sh
38
+ gem install <%= project_name %>
39
+ ```
40
+
41
+ ## Contributing
42
+
43
+ 1. Fork it
44
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
45
+ 3. Commit your changes (`git commit -am "Add some feature"`)
46
+ 4. Push to the branch (`git push origin my-new-feature`)
47
+ 5. Create new Pull Request
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ task :default => :spec
5
+
6
+ RSpec::Core::RakeTask.new
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Trap ^C
4
+ Signal.trap("INT") {
5
+ puts "\nCtrl-C detected. Exiting..."
6
+ sleep 1
7
+ exit
8
+ }
9
+
10
+ $:.unshift(File.expand_path("../../lib", __FILE__))
11
+ require "<%= project_name %>"
12
+ require "<%= underscored_name %>/cli"
13
+
14
+ <%= project_class_name %>::CLI.start(ARGV)
@@ -0,0 +1,12 @@
1
+ $:.unshift(File.expand_path("../", __FILE__))
2
+ require "<%= underscored_name %>/version"
3
+
4
+ module <%= project_class_name %>
5
+ autoload :Help, "<%= underscored_name %>/help"
6
+ autoload :Command, "<%= underscored_name %>/command"
7
+ autoload :RakeCommand, "<%= underscored_name %>/rake_command"
8
+ autoload :CLI, "<%= underscored_name %>/cli"
9
+ autoload :Sub, "<%= underscored_name %>/sub"
10
+ autoload :Completions, "<%= underscored_name %>/completions"
11
+ autoload :Completer, "<%= underscored_name %>/completer"
12
+ end
@@ -0,0 +1,166 @@
1
+ require "thor"
2
+ require "active_support" # for autoload
3
+ require "active_support/core_ext"
4
+
5
+ module <%= project_class_name %>
6
+ class CLI
7
+ def self.start(given_args=ARGV)
8
+ new(given_args).start
9
+ end
10
+
11
+ def self.thor_tasks
12
+ <%= project_class_name %>::Command.namespaced_commands
13
+ end
14
+
15
+ def initialize(given_args=ARGV, **config)
16
+ @given_args = given_args.dup
17
+ @config = config
18
+ end
19
+
20
+ def start
21
+ setup_auto_load
22
+ command_class = lookup(full_command)
23
+ if command_class
24
+ command_class.perform(full_command, thor_args)
25
+ else
26
+ main_help
27
+ end
28
+ end
29
+
30
+ def setup_auto_load
31
+ autoload_paths = [File.expand_path("../../", __FILE__)]
32
+ ActiveSupport::Dependencies.autoload_paths += autoload_paths
33
+ end
34
+
35
+ # thor_args normalized the args Array to work with our Thor command
36
+ # subclasses.
37
+ # 1. The namespace is stripped
38
+ # 2. The help is shifted in front if a help flag is detected
39
+ def thor_args
40
+ args = @given_args.clone
41
+
42
+ # Allow calling for help via:
43
+ # cli-template command help
44
+ # cli-template command -h
45
+ # cli-template command --help
46
+ # cli-template command -D
47
+ #
48
+ # as well thor's normal way:
49
+ #
50
+ # cli-template help command
51
+ help_args = args & help_flags
52
+ if help_args.empty?
53
+ args[0] = meth # reassigns the command without the namespace
54
+ else
55
+ # Allow using help flags at the end of the command to trigger help menu
56
+ args -= help_flags # remove "help" and help flags from args
57
+ args[0] = meth # first command will always be the meth now since
58
+ # we removed the help flags
59
+ args.unshift("help")
60
+ end
61
+ args.compact
62
+ end
63
+
64
+ def full_command
65
+ # Removes any args that starts with -, those are option args.
66
+ # Also remove "help" flag.
67
+ args = @given_args.reject {|o| o =~ /^-/ } - help_flags
68
+ command = args[0] # first argument should always be the command
69
+ <%= project_class_name %>::Command.autocomplete(command)
70
+ end
71
+
72
+ # 1. look up Thor tasks
73
+ # 2. look up Rake tasks - currently disabled
74
+ # 3. help menu with all commands when both Thor and Rake tasks are not found
75
+ #
76
+ # Example:
77
+ #
78
+ # lookup("sub:hello") => Sub
79
+ def lookup(full_command)
80
+ thor_task_found = <%= project_class_name %>::Command.namespaced_commands.include?(full_command)
81
+ if thor_task_found
82
+ return <%= project_class_name %>::Command.klass_from_namespace(namespace)
83
+ end
84
+
85
+ rake_task_found = <%= project_class_name %>::RakeCommand.namespaced_commands.include?(full_command)
86
+ if rake_task_found
87
+ return <%= project_class_name %>::RakeCommand
88
+ end
89
+ end
90
+
91
+ def version_flags
92
+ ["--version", "-v"]
93
+ end
94
+
95
+ # ["-h", "-?", "--help", "-D", "help"]
96
+ def help_flags
97
+ Thor::HELP_MAPPINGS + ["help"]
98
+ end
99
+
100
+ def namespace
101
+ return nil unless full_command
102
+
103
+ if full_command.include?(':')
104
+ words = full_command.split(':')
105
+ words.pop
106
+ words.join(':')
107
+ end
108
+ end
109
+
110
+ def meth
111
+ return nil unless full_command
112
+
113
+ if full_command.include?(':')
114
+ full_command.split(':').pop
115
+ else
116
+ full_command
117
+ end
118
+ end
119
+
120
+ # Allow calling version via:
121
+ # <%= project_name %> version
122
+ # <%= project_name %> --version
123
+ # <%= project_name %> -v
124
+ def version_flag?
125
+ args = @given_args
126
+ args.length == 1 && !(args & version_flags).empty?
127
+ end
128
+
129
+ def main_help
130
+ if version_flag?
131
+ <%= project_class_name %>::Main.perform("version", ["version"])
132
+ return
133
+ end
134
+
135
+ shell = Thor::Shell::Basic.new
136
+ shell.say "Commands:"
137
+ shell.print_table(thor_list, :indent => 2, :truncate => true)
138
+
139
+ # TODO: commenting out for now, feels weird to show the rake tasks
140
+ # automatically also by default. Maybe add an option for this.
141
+ # unless rake_list.empty?
142
+ # shell.say "\nCommands via rake:"
143
+ # shell.print_table(rake_list, :indent => 2, :truncate => true)
144
+ # end
145
+
146
+ shell.say "\n"
147
+ shell.say Help.text(:main) + "\n"
148
+ end
149
+
150
+ def thor_list
151
+ <%= project_class_name %>::Command.help_list(show_all_tasks)
152
+ end
153
+
154
+ def rake_list
155
+ list = <%= project_class_name %>::RakeCommand.formatted_rake_tasks(show_all_tasks)
156
+ list.map do |array|
157
+ array[0] = "<%= project_name %> #{array[0]}"
158
+ array
159
+ end
160
+ end
161
+
162
+ def show_all_tasks
163
+ @given_args.include?("--all") || @given_args.include?("-A")
164
+ end
165
+ end
166
+ end