Class: Brandish::Application Private
- Inherits:
-
Object
- Object
- Brandish::Application
- Includes:
- Commander::Methods
- Defined in:
- lib/brandish/application.rb,
lib/brandish/application/bench_command.rb,
lib/brandish/application/build_command.rb,
lib/brandish/application/serve_command.rb,
lib/brandish/application/initialize_command.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
The command line interface for Brandish.
Defined Under Namespace
Classes: BenchCommand, BuildCommand, InitializeCommand, ServeCommand
Constant Summary collapse
- PROGRESS_OPTIONS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Options that are passed to the
progress
method provided by Commander. This makes it look "nice." { title: " Building...", progress_str: "#", incomplete_str: " ", format: ":title <:progress_bar> :percent_complete%", complete_message: " Build complete!" }.freeze
- PROGRESS_WIDTH =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The width of all of the set text items in the progress bar. This is used to dynamically determine the with of the progress bar later on.
" Building... < > 000% ".length
Instance Attribute Summary collapse
-
#config_file ⇒ ::String
readonly
private
The name of the configure file.
-
#directory ⇒ ::String
readonly
private
The executing directory for the application.
Class Method Summary collapse
-
.call ⇒ void
private
Defines and runs the command line interface.
Instance Method Summary collapse
-
#call ⇒ void
private
Defines and runs the command line interface.
-
#config_file_path ⇒ ::Pathname
private
The path to the configuration file.
-
#configure_global_option ⇒ void
private
Defines the config global option.
-
#directory_global_option ⇒ void
private
Defines the directory global option.
-
#load_configuration_file ⇒ Configure
private
If the configuration isn't already loaded, load it; otherwise, just return the already loaded version of the configuration file.
-
#load_configuration_file! ⇒ Configure
private
Forces the configuration file to be loaded, even if it already was; this first resets the configuration using reset_configuration, then it loads the #config_file_path.
-
#program_information ⇒ void
private
The program information.
-
#progress(array) {|item| ... } ⇒ void
private
Creates a progress bar on the terminal based off of the given array.
Instance Attribute Details
#config_file ⇒ ::String (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The name of the configure file. This should be "brandish.config.rb"
,
but may change in the future (maybe Brandishfile
?).
24 25 26 |
# File 'lib/brandish/application.rb', line 24 def config_file @config_file end |
#directory ⇒ ::String (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The executing directory for the application. This is provided with the
global option -d
. Using this should be the same as using cd
and
executing the command.
31 32 33 |
# File 'lib/brandish/application.rb', line 31 def directory @directory end |
Class Method Details
.call ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Defines and runs the command line interface.
37 38 39 |
# File 'lib/brandish/application.rb', line 37 def self.call new.call end |
Instance Method Details
#call ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Defines and runs the command line interface.
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/brandish/application.rb', line 51 def call program_information configure_global_option directory_global_option command(:initialize) { |c| InitializeCommand.define(self, c) } command(:bench) { |c| BenchCommand.define(self, c) } command(:build) { |c| BuildCommand.define(self, c) } command(:serve) { |c| ServeCommand.define(self, c) } alias_command(:init, :initialize) default_command(:build) run! end |
#config_file_path ⇒ ::Pathname
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The path to the configuration file. This is used for #load_configuration_file!.
134 135 136 |
# File 'lib/brandish/application.rb', line 134 def config_file_path @directory / @config_file end |
#configure_global_option ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Defines the config global option. This sets #config_file to its default file, and defines an option that can set it.
81 82 83 84 |
# File 'lib/brandish/application.rb', line 81 def configure_global_option @config_file = "brandish.config.rb" global_option("--config FILE") { |f| @config_file = f } end |
#directory_global_option ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Defines the directory global option. This sets #directory to its default value, and defines an option that can set it.
90 91 92 93 94 95 |
# File 'lib/brandish/application.rb', line 90 def directory_global_option @directory = Pathname.new(Dir.pwd) global_option("--directory PATH") do |path| @directory = Pathname.new(path).(Dir.pwd) end end |
#load_configuration_file ⇒ Configure
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
If the configuration isn't already loaded, load it; otherwise, just return the already loaded version of the configuration file.
142 143 144 |
# File 'lib/brandish/application.rb', line 142 def load_configuration_file Brandish.configuration || load_configuration_file! end |
#load_configuration_file! ⇒ Configure
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Forces the configuration file to be loaded, even if it already was; this first resets the configuration using Brandish.reset_configuration, then it loads the #config_file_path. If no configuration was provided, it fails; if it didn't load properly, it fails.
154 155 156 157 158 159 160 161 |
# File 'lib/brandish/application.rb', line 154 def load_configuration_file! Brandish.reset_configuration load config_file_path.to_s fail "No configuration provided" unless Brandish.configuration Brandish.configuration rescue LoadError fail "No configuration provided" end |
#program_information ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
The program information. This is for use with Commander.
67 68 69 70 71 72 73 74 75 |
# File 'lib/brandish/application.rb', line 67 def program_information program :name, "Brandish" program :version, Brandish::VERSION program :help_formatter, :compact program :help_paging, false program :description, "A multi-format document generator." program :help, "Author", "Jeremy Rodi <[email protected]>" program :help, "License", "MIT License Copyright (c) 2017 Jeremy Rodi" end |
#progress(array) {|item| ... } ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Creates a progress bar on the terminal based off of the given array.
This mostly passes everything on to the progress
method provided by
Commander, but with a few options added.
122 123 124 125 126 127 128 |
# File 'lib/brandish/application.rb', line 122 def progress(array, &block) # rubocop:disable Style/GlobalVars width = $terminal.terminal_size[0] - PROGRESS_WIDTH # rubocop:enable Style/GlobalVars = PROGRESS_OPTIONS.merge(width: width) super(array, , &block) end |