#!/usr/bin/env ruby lib = File.expand_path('../lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'git/superproject' if (command = ARGV.shift)&.start_with? '++' name = command[2..-1] command = nil end # TODO: acquire flock on "~/.git/multi/superprojects.config" case (command ||= ARGV.shift) when /\A--/ case command when '--version' then Git::Superproject::Commands.version when '--help' then Git::Superproject::Commands.help else config = Git::Superproject::Config.from(Git::SUPERPROJECTS_CONFIG) case command when '--config' then puts config.to_json else unless name warn 'No superproject specified... aborting!' exit(-1) end case command when '--list' then config.list(name) when '--add' then config.add(name, *ARGV) when '--remove' then config.remove(name, *ARGV) when '--edit' finder = 'fzf --print0 --multi --border --height=50%' candidates = ARGF.readlines.map(&:strip) # repos to select from... config.edit(name, finder, candidates) else abort \ "Unknown 'git superproject' command: #{command}\n\n" \ '(use --help/-h to list all available commands)' end config.save(Git::SUPERPROJECTS_CONFIG) end end when nil, '', '-h' Git::Superproject::Commands.help end # TODO: release flock on "~/.git/multi/superprojects.config" # That's all Folks!