lib/jive/cli.rb in jive-0.2.1 vs lib/jive/cli.rb in jive-0.2.2

- old
+ new

@@ -9,21 +9,22 @@ class App < Thor def self.exit_on_failure? true end + desc "cd <org>/<project>", "cd to ~/src/github.com/<org>/<project>" + def cd(slug) + runner.run_safely do + Git.new(runner).cd(slug) + end + end + desc "clone <org>/<project>", "git clone to ~/src/github.com/<org>/<project>" def clone(slug) - target_dir = Pathname.new(Dir.home).join("src/github.com/#{slug}") - run_each([ - [:mkdir, "-p", target_dir.parent.to_s], - [:git, "clone", "git@github.com:#{slug}.git", target_dir] - ]) - after_run([ - ["cd", target_dir], - ["setenv", "JIVE_LAST_RUN=#{Time.now.to_i}"] - ]) + runner.run_safely do + Git.new(runner).clone(slug) + end end desc "setup", "provide instructions to integrate into shell" def setup say <<~MESSAGE @@ -33,37 +34,11 @@ MESSAGE end private - COMMAND_MAP = { - cd: "/usr/bin/cd", - echo: "/usr/bin/echo", - git: "/usr/bin/git", - mkdir: "/usr/bin/mkdir" - }.freeze - - def run_each(tasks) - tasks.each do |task| - break unless execute(task) - end - end - - def execute(command, env: {}) - system(env, expand(command)) - end - - def after_run(tasks) - finalizer_fd = 9 - pipe = IO.new(finalizer_fd) - pipe.puts(tasks.map { |x| x.join(":") }.join("\n")) - end - - def expand(command) - Array(command) - .flatten - .map { |x| COMMAND_MAP.fetch(x, x).to_s } - .join(" ") + def runner + @runner ||= ::Jive::Shell.new end end end end