# 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 Git.new.semantic_help end method_option :host, type: :string, default: "github.com" desc "clone /", "git clone to ~/src/github.com//" def clone(slug) host = options[:host] Jive.shell.run_safely { Git.new(Jive.shell).clone(slug, host: host) } end end) desc "cd /", "cd to ~/src/github.com//" def cd(slug) Jive.shell.run_safely { Git.new(Jive.shell).cd(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 "pr URL", "pull request" def pr(url = Repo.current.canonical_url) return say("Invalid url") && exit(1) unless url pr = PullRequest.new(url) pr.edit(ENV["EDITOR"]) end desc "setup", "provide instructions to integrate into shell" def setup print "source #{::Jive.root.join("jive.sh")}" end end end end