#!/usr/bin/env ruby require 'rubygems' require 'gli' require_relative '../lib/git_helper' include GLI::App program_desc 'GitHub and GitLab workflow scripts.' version GitHelper::VERSION autocomplete_commands false wrap_help_text :verbatim program_long_desc """ DOCUMENTATION For documentation and help in setting up your Git configuration files, see Git Helper's GitHub repo: https://github.com/emmasax4/git_helper """ arg :old_owner arg :new_owner desc "Update a repository's remote URLs from an old GitHub owner to a new owner." command 'change-remote' do |c| c.action do |global_options, options, args| require_relative '../lib/git_helper/change_remote.rb' raise ArgumentError, 'You must specify an old owner and a new owner' unless args.count == 2 GitHelper::ChangeRemote.new.execute(args[0], args[1]) end end desc "Checks out the default branch of a repo based on the local remote branches." command 'checkout-default' do |c| c.action do |global_options, options, args| require_relative '../lib/git_helper/checkout_default.rb' GitHelper::CheckoutDefault.new.execute end end desc "Clean a repository's git branches." command 'clean-branches' do |c| c.action do |global_options, options, args| require_relative '../lib/git_helper/clean_branches.rb' GitHelper::CleanBranches.new.execute end end desc "Creates an empty commit with a basic commit message." command 'empty-commit' do |c| c.action do |global_options, options, args| require_relative '../lib/git_helper/empty_commit.rb' GitHelper::EmptyCommit.new.execute end end desc 'Create a GitLab merge request from the current branch.' command 'merge-request' do |c| c.switch [:c, :create], desc: 'Create a new pull request' c.switch [:m, :merge], desc: 'Merge an existing pull request' c.action do |global_options, options, args| require_relative '../lib/git_helper/merge_request.rb' raise ArgumentError, "You must specify an action (either '-m'/'--merge' or '-c'/'--create')" unless options[:create] || options[:merge] options = global_options.merge(options) if options[:create] GitHelper::GitLabMergeRequest.new.create elsif options[:merge] GitHelper::GitLabMergeRequest.new.merge end end end arg :new_branch_name, optional: true desc 'Create a new branch for features, bug fixes, or experimentation.' command 'new-branch' do |c| c.action do |global_options, options, args| require_relative '../lib/git_helper/new_branch.rb' GitHelper::NewBranch.new.execute(args[0]) end end desc 'Create a GitHub pull request from the current branch.' command 'pull-request' do |c| c.switch [:c, :create], desc: 'Create a new pull request' c.switch [:m, :merge], desc: 'Merge an existing pull request' c.action do |global_options, options, args| require_relative '../lib/git_helper/pull_request.rb' raise ArgumentError, "You must specify an action (either '-m'/'--merge' or '-c'/'--create')" unless options[:create] || options[:merge] options = global_options.merge(options) if options[:create] GitHelper::GitHubPullRequest.new.create elsif options[:merge] GitHelper::GitHubPullRequest.new.merge end end end exit run(ARGV)