# frozen_string_literal: true require "cli/ui" 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 "issue SUBCOMMAND ...ARGS", "issue things" subcommand "issue", (Class.new(Thor) do desc "list ", "List the issues" def list(type = Issue.what_type?) issues = Issue.for(type) issue = Jive.prompt?(issues, display: ->(x) { x.file_name }) issue.edit end desc "create ", "Create a new issue" def create(type = Issue.what_type?) issue = Issue.create!(name: ask("Name:"), type: type) issue.edit 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", "pull request" def pr pr = PullRequest.new(repo: Repo.current) 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