Module: App
- Defined in:
- lib/core/api.rb,
lib/core/git.rb,
lib/core/pom.rb,
lib/core/ssh.rb,
lib/core/ebay.rb,
lib/core/jira.rb,
lib/core/enums.rb,
lib/core/mysql.rb,
lib/core/tools.rb,
lib/core/config.rb,
lib/core/terminal.rb,
lib/core/validate.rb,
lib/core/encrypter.rb,
lib/brightpearl_cli.rb,
lib/core/git_delete.rb,
lib/core/sql_update.rb,
lib/core/utils_files.rb,
lib/core/utils_tools.rb,
lib/core/ebay_factory.rb,
lib/core/utils_routes.rb,
lib/core/utils_strings.rb
Defined Under Namespace
Classes: API, Config, Ebay, EbayFactory, Encrypter, Enum, Git, GitDelete, Jira, MySQL, Pom, SSH, SqlUpdate, Terminal, Tools, UtilsFiles, UtilsRoutes, UtilsStrings, UtilsTools, Validate
Constant Summary collapse
- DEFAULT_OPTION =
"\xe2\x80\x94 \x1B[38;5;148mDefault\x1B[0m"
Class Method Summary collapse
Class Method Details
.execute ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 |
# File 'lib/brightpearl_cli.rb', line 56 def self.execute begin unless !ARGV.any? || ARGV[0] == 'setup' || ARGV[0] == 'x' App::Config.initialize end Convoy::App.create do |app| # COLOR OF TITLE TEXT title_color = 255 beta = App::Config::param(ConfigUnique::BETA) == 'true' ? true : false app.version VERSION app.summary "\x1B[38;5;166mBRIGHTPEARL-CLI\x1B[0m \x1B[38;5;240m\xe2\x80\x94 BETA\x1B[0m" app.description "\x1B[38;5;#{title_color}mA command line utility for Brightpearl developers and QAs.\nUsed for automating daily work flows & completing repetitive tasks quicker with less errors.\nDesigned to work from anywhere on your workstation.\n\nUse #{App::Terminal::format_command('app')}\x1B[38;5;#{title_color}m or #{App::Terminal::format_command('bp')}\x1B[38;5;#{title_color}m to run.\x1B[0m" # BUILD app.command :build, :aliases => [:b] do |build| build.summary 'Build (and deploy) Java services' build. do |opts| opts.opt :serviceOnly, "Build service only #{DEFAULT_OPTION}", :short => '-s', :long => '--service-only', :type => :boolean opts.opt :apiOnly, 'Build API only', :short => '-a', :long => '--api-only', :type => :boolean opts.opt :both, 'Build both', :short => '-b', :long => '--both', :type => :boolean opts.opt :deploy, 'Deploy to SkyFactory', :short => '-d', :long => '--deploy', :type => :boolean end build.action do |opts, args| AppCommand::Build.new(opts, args).execute end end # FIX app.command :fix, :aliases => [:f] do |fix| fix.summary 'Quick fixes for common problems' fix. do |opts| opts.opt :login_sessions, 'Fix login problem(s) by clearing out the sessions table.', :short => '-l', :long => '--login-sessions', :type => :boolean opts.opt :sql_mode, 'Fix problem when SQL goes into "STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION" mode.', :short => '-s', :long => '--sql-mode', :type => :boolean end fix.action do |opts, args| AppCommand::Fix.new(opts, args).execute end end # GIT app.command :git, :aliases => [:g] do |git| git.summary 'All git related functionality' # GIT BRANCH git.command :branch, :aliases => [:b] do |git_branch| git_branch.summary 'List local/remote branches' git_branch. do |opts| opts.opt :local, 'List local branches', :short => '-l', :long => '--local', :type => :boolean opts.opt :remote, 'List remote branches', :short => '-r', :long => '--remote', :type => :boolean opts.opt :sortDate, 'Sort by date', :short => '-d', :long => '--sort-date', :type => :boolean opts.opt :sortRefname, "Sort by branch name #{DEFAULT_OPTION}", :short => '-n', :long => '--sort-refname', :type => :boolean opts.opt :detailed, 'Show a more detailed output w/Jira data, etc. (takes longer)', :short => '-D', :long => '--detailed', :type => :boolean end git_branch.action do |opts, args| AppCommand::GitBranch.new(opts, args).execute end end # GIT CHECKOUT git.command :checkout, :aliases => [:c, :co] do |git_checkout| git_checkout.summary 'Create & checkout branches' git_checkout. do |opts| opts.opt :branch, 'Create a branch locally', :short => '-b', :long => '--branch', :type => :boolean opts.opt :branch_origin, 'Create a branch and push to origin', :short => '-B', :long => '--branch-origin', :type => :boolean opts.opt :update, "Update branch after checkout. Will run a 'git pull' & 'git merge master'", :short => '-u', :long => '--update', :type => :boolean opts.opt :updatePush, 'Same as --update but will also push to origin', :short => '-U', :long => '--update-push', :type => :boolean end git_checkout.action do |opts, args| AppCommand::GitCheckout.new(opts, args).execute end end # GIT DELETE git.command :delete, :aliases => [:d] do |git_delete| git_delete.summary 'Delete branch(es)' git_delete. do |opts| opts.opt :delete_local, 'Delete local branch', :short => '-l', :long => '--delete-local', :type => :boolean opts.opt :delete_remote, 'Delete remote branch', :short => '-r', :long => '--delete-remote', :type => :boolean opts.opt :delete_both, 'Delete both local & remote branches', :short => '-b', :long => '--delete-both', :type => :boolean end git_delete.action do |opts, args| AppCommand::GitDelete.new(opts, args).execute end end # GIT MERGE git.command :merge, :aliases => [:m] do |git_merge| git_merge.summary 'Merge branch(es)' d = "Accepts one #{App::Terminal::format_action('mandatory')} primary argument \xe2\x80\x94 the name of the source branch." d << "\nAccepts one #{App::Terminal::format_action('optional')} secondary argument \xe2\x80\x94 the name of the target branch." d << "\n" d << "\nIf no secondary argument is given, target branch will be #{App::Terminal::format_branch('current-branch')}" d << "\n" d << "\n #{App::Terminal::format_command('bp g m source_branch')} \x1B[0m" d << "\n #{App::Terminal::format_command('bp g m source_branch target_branch')} \x1B[0m" d << "\n" d << "\nTo merge multiple branches use a comma-separated string (without spaces):" d << "\n" d << "\n #{App::Terminal::format_command('bp g m sb1,sb2,sb3')}" d << "\n #{App::Terminal::format_command('bp g m sb1,sb2,sb3 target_branch')}" d << "\n" d << "\nAlternatively, use the #{App::Terminal::format_flag('o', false)} and #{App::Terminal::format_flag('f', false)} flags to specify your source branches using a temporary file:" d << "\n" d << "\n #{App::Terminal::format_flag('o', false)} opens #{App::Terminal::format_directory(App::Git::GIT_MERGE_DEFAULT_FILE)}" d << "\n #{App::Terminal::format_flag('f', false)} parses the contents of #{App::Terminal::format_directory(App::Git::GIT_MERGE_DEFAULT_FILE)} as source branches (one branch per line)" d << "\n" d << "\n #{App::Terminal::format_command('bp g m -o')} \x1B[0m" d << "\n #{App::Terminal::format_command('bp g m -f')} \x1B[0m" d << "\n #{App::Terminal::format_command('bp g m -f target_branch')} \x1B[0m" git_merge.description d git_merge. do |opts| opts.opt :open_file, "Creates (and opens) #{App::Terminal::format_directory(App::Git::GIT_MERGE_DEFAULT_FILE)}", :short => '-o', :long => '--open-file', :type => :boolean opts.opt :from_file, 'Get branch names from file (1 branch per line)', :short => '-f', :long => '--from-file', :type => :boolean opts.opt :delete_source_branches_local, "Delete all source branches (locally) in #{App::Terminal::format_directory(App::Git::GIT_MERGE_DEFAULT_FILE)}", :short => '-d', :long => '--delete-local', :type => :boolean opts.opt :delete_source_branches_remote, "Delete all source branches (remotely) in #{App::Terminal::format_directory(App::Git::GIT_MERGE_DEFAULT_FILE)}", :short => '-D', :long => '--delete-remote', :type => :boolean opts.opt :sanity_check, 'Run sanity check. Submit source/target branches same as you would during a merge.', :short => '-s', :long => '--sanity-check', :type => :boolean opts.opt :build_services, "Determine what services need to be built before merging to #{App::Terminal::format_branch(App::Git::MASTER)}.", :short => '-b', :long => '--build-services', :type => :boolean opts.opt :push_changes, 'Update all remote source branches with merge changes (IE: Confict resolutions)', :short => '-P', :long => '--push-changes', :type => :boolean end git_merge.action do |opts, args| AppCommand::GitMerge.new(opts, args).execute end end # GIT PULL git.command :pull, :aliases => [:p] do |git_pull| git_pull.summary 'Pull from origin' git_pull.action do |opts, args| AppCommand::GitPull.new(opts, args).execute end end # GIT PUSH git.command :push, :aliases => [:P] do |git_push| git_push.summary 'Push to origin' git_push.action do |opts, args| AppCommand::GitPush.new(opts, args).execute end end # GIT STASH git.command :stash, :aliases => [:S] do |git_stash| git_stash.summary 'Show your current stashes' git_stash.action do |opts, args| AppCommand::GitStash.new(opts, args).execute end end # GIT UPDATE git.command :update, :aliases => [:u] do |git_update| git_update.summary 'Update branch(es)' git_update. do |opts| opts.opt :push, 'Push updates to origin', :short => '-P', :long => '--push', :type => :boolean end git_update.action do |opts, args| AppCommand::GitUpdate.new(opts, args).execute end end # GIT (DEFAULT) git.action do system('bp g -h') end end # JIRA app.command :jira, :aliases => [:j] do |jira| jira.summary 'Access the Jira API' # JIRA CARD jira.command :card, :aliases => [:c] do |jira_card| jira_card.summary 'Get detailed information about a card' jira_card.action do |opts, args| AppCommand::JiraCard.new(opts, args).execute end end # JIRA (DEFAULT) jira.action do system('bp j -h') end end # RESET app.command :reset, :aliases => [:R] do |reset| reset.summary 'Reset various things within the App' reset. do |opts| opts.opt :fitnesseDump, 'Reset the Fitnesse Dump on your VM', :short => '-f', :long => '--fitnesse-dump', :type => :boolean end reset.action do |opts, args| AppCommand::Reset.new(opts, args).execute end end # PRODUCTION app.command :production, :aliases => [:p] do |production| production.summary 'Everything to do with production servers' # PRODUCTION LOGS production.command :logs, :aliases => [:l] do |production_logs| production_logs.summary 'Scan production logs' production_logs. do |opts| opts.opt :watchPHP, "Watch PHP logs #{DEFAULT_OPTION}", :short => '-p', :long => '--watch-php-logs', :type => :boolean opts.opt :watchJava, 'Watch Java logs', :short => '-j', :long => '--watch-java-logs', :type => :boolean opts.opt :skipFetch, 'Skip fetching of new logs (quicker)', :short => '-s', :long => '--skip-fetch', :type => :boolean opts.opt :compare, 'Compare logs between 2 versions (requires 2 parameters -- source & target version)', :short => '-c', :long => '--compare', :type => :boolean opts.opt :versionList, 'See a list of all versions which have been captured.', :short => '-V', :long => '--version-list', :type => :boolean end production_logs.action do |opts, args| AppCommand::ProductionLogs.new(opts, args).execute end end # PRODUCTION (DEFAULT) production.action do system('bp p -h') end end # REVIEW app.command :review, :aliases => [:r] do |review| review.summary 'Perform a quick code review' review.action do |opts, args| AppCommand::Review.new(opts, args).execute end end # SCRIPTS app.command :scripts, :aliases => [:s] do |scripts| scripts.summary 'Quick & dirty scripts' # SCRIPTS API DOCS scripts.command :api_docs, :aliases => [:a] do |scripts_api_docs| scripts_api_docs.summary 'Build API docs' scripts_api_docs.action do |opts, args| AppCommand::ScriptsApiDocs.new(opts, args).execute end end # SCRIPTS BRANCH CLEANER scripts.command :branch_cleaner, :aliases => [:b] do |scripts_branch_cleaner| scripts_branch_cleaner.summary 'Identify (and remove) old branches' scripts_branch_cleaner. do |opts| opts.opt :scanLocal, 'Find local branches to remove', :short => '-l', :long => '--scan-local', :type => :boolean opts.opt :scanRemote, 'Find remote branches to remove', :short => '-r', :long => '--scan-remote', :type => :boolean opts.opt :anyName, "Find branches with any last committer, not just: #{App::Config.param(App::Config::GIT_USERNAME)}", :short => '-a', :long => '--any-name', :type => :boolean end scripts_branch_cleaner.action do |opts, args| AppCommand::ScriptsBranchCleaner.new(opts, args).execute end end # SCRIPTS PHP SONAR scripts.command :sonar, :aliases => [:s] do |scripts_sonar| scripts_sonar.summary 'Run PHP Sonar (CodeSniffer)' scripts_sonar.action do |opts, args| AppCommand::ScriptsSonar.new(opts, args).execute end end # SCRIPTS SQL-UPDATE scripts.command :sql_update, :aliases => [:S] do |scripts_sql_update| scripts_sql_update.summary 'Finish off a SQL Update' scripts_sql_update.action do |opts, args| AppCommand::ScriptsSqlUpdate.new(opts, args).execute end end # SCRIPTS COLOR scripts.command :color, :aliases => [:c] do |scripts_color| scripts_color.summary 'Shows a list of bash/ruby color codes (256-bit)' scripts_color.action do |opts, args| AppCommand::ScriptsColor.new(opts, args).execute end end # SCRIPTS POM-FIXER scripts.command :pom_fixer, :aliases => [:p] do |scripts_pom_fixer| scripts_pom_fixer.summary 'Finds and fixes feature-tagged POM files.' scripts_pom_fixer. do |opts| opts.opt :forMaster, 'Remove branch tags completely (do before merging to master)', :short => '-m', :long => '--for-master', :type => :boolean end scripts_pom_fixer.action do |opts, args| AppCommand::ScriptsPomFixer.new(opts, args).execute end end # SCRIPTS (DEFAULT) scripts.action do system('bp s -h') end end # SSH - SSH app.command :ssh, :aliases => [:sh] do |ssh| ssh.summary 'SSH into various stuff.' ssh.action do |opts, args| AppCommand::SSH.new(opts, args).execute end end # TAIL app.command :tail, :aliases => [:T] do |tail| tail.summary 'Tail various logs' tail. do |opts| opts.opt :catalina, "Tail #{App::Terminal::format_directory('/var/log/tomcat/*/catalina.out')}", :short => '-c', :long => '--catalina', :type => :boolean opts.opt :access, "Tail #{App::Terminal::format_directory('/var/log/tomcat/*/access*')}", :short => '-a', :long => '--access', :type => :boolean opts.opt :php, "Tail #{App::Terminal::format_directory('/var/log/php/php.log')}", :short => '-p', :long => '--php', :type => :boolean opts.opt :phpunit, "Tail #{App::Terminal::format_directory('/tmp/phpunit.error.log')}", :short => '-P', :long => '--php-unit', :type => :boolean end tail.action do |opts, args| AppCommand::Tail.new(opts, args).execute end end # TEST app.command :test, :aliases => [:t] do |test| test.summary 'Run various tests' test. do |opts| opts.opt :cucumber, 'Run Cucumber tests', :short => '-c', :long => '--cucumber', :type => :boolean opts.opt :fitnesse, 'Run FitNesse tests', :short => '-f', :long => '--fitnesse', :type => :boolean opts.opt :php, "Run PHPUnit tests #{DEFAULT_OPTION}", :short => '-p', :long => '--php-unit', :type => :boolean opts.opt :behat, 'Run Behat tests', :short => '-b', :long => '--behat', :type => :boolean opts.opt :ruby, 'Run Ruby UI tests', :short => '-r', :long => '--ruby-ui', :type => :boolean end test.action do |opts, args| AppCommand::Test.new(opts, args).execute end end # UPDATE app.command :update, :aliases => [:u] do |update| update.summary 'Check for updates' update.action do |opts, args| AppCommand::Update.new(opts, args).execute end end # X - SETUP app.command :setup, :aliases => [:x] do |setup| setup.summary 'Setup your configuration file' setup.action do |opts, args| AppCommand::Setup.new(opts, args).execute end end # BRIGHTPEARL/BP (DEFAULT) app.action do system('bp -h') end end rescue RuntimeError => e puts e. puts e.backtrace end end |