forked from a/repotool
134 lines
4.4 KiB
Lua
Executable File
134 lines
4.4 KiB
Lua
Executable File
-- Add src/lib to package path
|
|
local script_path = debug.getinfo(1).source:match("@(.+)") or arg[0]
|
|
local script_dir = script_path:match("(.*/)")
|
|
if not script_dir then
|
|
script_dir = "./"
|
|
end
|
|
package.path = script_dir .. "lib/?.lua;" .. script_dir .. "src/?.lua;" .. script_dir .. "src/lib/?.lua;" .. package.path
|
|
|
|
local cli = require("cli")
|
|
local json = require("json")
|
|
|
|
-- Load command modules
|
|
local get_command = require("get_command")
|
|
local worktree = require("worktree")
|
|
local open_command = require("open_command")
|
|
|
|
-- Create the main command with subcommands
|
|
local app = cli.cmd {
|
|
'repotool',
|
|
name = 'repotool',
|
|
version = '0.1.0',
|
|
desc = 'repo tool',
|
|
subs = {
|
|
-- Get command
|
|
cli.cmd {
|
|
'get', 'g',
|
|
desc = 'gets repo if not found',
|
|
term = cli.all {
|
|
repo = cli.arg {
|
|
'repo',
|
|
desc = 'URL to repo',
|
|
required = true,
|
|
},
|
|
ssh_user = cli.opt {
|
|
'--ssh-user',
|
|
desc = 'ssh user to clone with',
|
|
vdesc = 'USER',
|
|
},
|
|
http_user = cli.opt {
|
|
'--http-user',
|
|
desc = 'http user to clone with',
|
|
vdesc = 'USER',
|
|
},
|
|
http_pass = cli.opt {
|
|
'--http-pass',
|
|
desc = 'http pass to clone with',
|
|
vdesc = 'PASS',
|
|
},
|
|
method = cli.opt {
|
|
'--method', '-m',
|
|
desc = 'the method to clone the repo with',
|
|
vdesc = 'METHOD',
|
|
},
|
|
}:and_then(function(args)
|
|
get_command({
|
|
repo = args.repo,
|
|
ssh_user = args.ssh_user or 'git',
|
|
http_user = args.http_user or '',
|
|
http_pass = args.http_pass or '',
|
|
method = args.method or 'ssh',
|
|
})
|
|
return 0
|
|
end),
|
|
},
|
|
-- Worktree command with subcommands
|
|
cli.cmd {
|
|
'worktree', 'w', 'wt',
|
|
desc = 'manage git worktrees',
|
|
subs = {
|
|
-- List subcommand
|
|
cli.cmd {
|
|
'list', 'ls',
|
|
desc = 'list existing worktrees for this repo',
|
|
term = cli.val():and_then(function()
|
|
worktree.handle_list()
|
|
return 0
|
|
end),
|
|
},
|
|
-- Get subcommand
|
|
cli.cmd {
|
|
'get',"new","create","n","c",
|
|
desc = 'create or go to a worktree',
|
|
term = cli.all {
|
|
name = cli.arg {
|
|
'name',
|
|
desc = 'Name of the worktree',
|
|
required = true,
|
|
},
|
|
}:and_then(function(args)
|
|
worktree.handle_get(args.name)
|
|
return 0
|
|
end),
|
|
},
|
|
-- Root subcommand
|
|
cli.cmd {
|
|
'root', 'back', 'r', 'return',
|
|
desc = 'return to the root directory of the original repo',
|
|
term = cli.val():and_then(function()
|
|
worktree.handle_root()
|
|
return 0
|
|
end),
|
|
},
|
|
-- Remove subcommand
|
|
cli.cmd {
|
|
'remove', 'rm', 'delete', 'del',
|
|
desc = 'remove a worktree',
|
|
term = cli.all {
|
|
name = cli.arg {
|
|
'name',
|
|
desc = 'Name of the worktree to remove',
|
|
required = true,
|
|
},
|
|
}:and_then(function(args)
|
|
worktree.handle_remove(args.name)
|
|
return 0
|
|
end),
|
|
},
|
|
},
|
|
},
|
|
-- Open command
|
|
cli.cmd {
|
|
'open', 'o',
|
|
desc = 'open the current repository in web browser',
|
|
term = cli.val():and_then(function()
|
|
open_command({})
|
|
return 0
|
|
end),
|
|
},
|
|
},
|
|
}
|
|
|
|
-- Run the app
|
|
os.exit(app:run())
|