Class: CLIClassTool::Common
- Inherits:
-
Object
- Object
- CLIClassTool::Common
- Includes:
- Logger
- Defined in:
- lib/cli_class_tool/common.rb
Overview
Common utility class providing logging, configuration, and shell execution methods
Constant Summary collapse
- ACTION_LIST =
List of available actions for this class
[ :list_actions ]
- ACTION_HELP =
Help text for actions
{}
Class Method Summary collapse
-
.inherited(subclass) ⇒ Object
Hook to enforce namespace loading at load time.
- .run(path, cmd, check_err = true) ⇒ Object
Instance Method Summary collapse
-
#initialize(path = ".", caller_obj = self) ⇒ Common
constructor
Simple initializer for a Common object.
-
#list_actions(opts) ⇒ Integer
List available actions.
-
#run(cmd, check_err = true) ⇒ String
Run a shell command.
-
#runGit(cmd, opts = {}, check_err = true) ⇒ String
Run a git command.
-
#runGitInteractive(cmd, opts = {}, check_err = true) ⇒ Boolean
Run a git command interactively.
-
#runSystem(cmd, check_err = true) ⇒ Boolean
Run a shell command using system() (interactive).
Methods included from Logger
Constructor Details
#initialize(path = ".", caller_obj = self) ⇒ Common
Simple initializer for a Common object
149 150 151 152 |
# File 'lib/cli_class_tool/common.rb', line 149 def initialize(path=".", caller_obj=self) @path = path @parent_module = obj_to_parent_mod(caller_obj) end |
Class Method Details
.inherited(subclass) ⇒ Object
Hook to enforce namespace loading at load time
104 105 106 107 108 109 110 111 |
# File 'lib/cli_class_tool/common.rb', line 104 def self.inherited(subclass) if subclass.name parts = subclass.name.to_s.split('::') if parts.size <= 1 raise "CLIClassTool action classes must be defined within a named module/class namespace" end end end |
Instance Method Details
#list_actions(opts) ⇒ Integer
List available actions
216 217 218 219 |
# File 'lib/cli_class_tool/common.rb', line 216 def list_actions(opts) puts parent_module.getActionAttr("ACTION_LIST").map(){|x| parent_module.actionToString(x)}.join("\n") return 0 end |
#run(cmd, check_err = true) ⇒ String
Run a shell command
160 161 162 163 164 165 |
# File 'lib/cli_class_tool/common.rb', line 160 def run(cmd, check_err = true) cmd_debug('', cmd) ret = `cd #{@path} && #{cmd}`.chomp() abort_if_err(check_err, $?, ret) return ret end |
#runGit(cmd, opts = {}, check_err = true) ⇒ String
Run a git command
191 192 193 194 195 196 |
# File 'lib/cli_class_tool/common.rb', line 191 def runGit(cmd, opts={}, check_err = true) cmd_debug('git', cmd) ret = `cd #{@path} && #{opts[:env]} git #{cmd}`.chomp() abort_if_err(check_err, $?, ret) return ret end |
#runGitInteractive(cmd, opts = {}, check_err = true) ⇒ Boolean
Run a git command interactively
205 206 207 208 209 210 |
# File 'lib/cli_class_tool/common.rb', line 205 def runGitInteractive(cmd, opts={}, check_err = true) cmd_debug('git interactive', cmd) ret = system("cd #{@path} && #{opts[:env]} git #{cmd}") abort_if_err(check_err, $?) return ret end |
#runSystem(cmd, check_err = true) ⇒ Boolean
Run a shell command using system() (interactive)
177 178 179 180 181 182 |
# File 'lib/cli_class_tool/common.rb', line 177 def runSystem(cmd, check_err = true) cmd_debug('interactive', cmd) ret = system("cd #{@path} && #{cmd}") abort_if_err(check_err, $?) return ret end |