# frozen_string_literal: true require "pathname" require "thor" require "yaml" require "jive" module Jive module Cli class App < Thor package_name "jive" def self.exit_on_failure? true end def self.handle_no_command_error(name) ::Jive::Cli::App.start(["exec", name]) end desc "docker SUBCOMMAND ...ARGS", "docker commands" subcommand "docker", (Class.new(Thor) do desc "build", "build the Dockerfile in the current directory" def build Docker.new.build(Pathname.pwd) end desc "launch", "launch a shell into a container" def launch Docker.new.launch(Pathname.pwd) end desc "size", "print the size of each image" def size Docker.new.size(Pathname.pwd) end end) desc "git SUBCOMMAND ...ARGS", "git commands" subcommand "git", (Class.new(Thor) do desc "semantic", "Print help for semantic commit messages" def semantic say <<~MESSAGE Format: (): is optional feat: add hat wobble ^--^ ^------------^ | | | +-> Summary in present tense. | +-------> Type: chore, docs, feat, fix, refactor, style, or test. chore: updating grunt tasks etc; no production code change docs: changes to the documentation feat: new feature for the user, not a new feature for build script fix: bug fix for the user, not a fix to a build script refactor: refactoring production code, eg. renaming a variable style: formatting, missing semi colons, etc; no production code change test: adding missing tests, refactoring tests; no production code change MESSAGE end end) desc "cd /", "cd to ~/src/github.com//" def cd(slug) Jive.shell.run_safely { Git.new(Jive.shell).cd(slug) } end desc "clone /", "git clone to ~/src/github.com//" def clone(slug) Jive.shell.run_safely { Git.new(Jive.shell).clone(slug) } end desc "exec ", "run command from jive.yml" def exec(command) path = Pathname.pwd.join("jive.yml") return shell.error("Error: jive.yml not found") unless path.exist? Jive.shell.run_safely do Jive.shell.execute(YAML.safe_load(path.read).dig("commands", command)) end end desc "bootstrap", "bootstrap the current project" def bootstrap Project .new(Pathname.pwd) .bootstrap(Jive.shell) end desc "setup", "provide instructions to integrate into shell" def setup print "source #{::Jive.root.join("jive.sh")}" end end end end