forked from a/repotool
115 lines
3.6 KiB
Lua
115 lines
3.6 KiB
Lua
|
|
-- 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_command = require("worktree_command")
|
||
|
|
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
|
||
|
|
cli.cmd {
|
||
|
|
'worktree', 'w', 'wt',
|
||
|
|
desc = 'goes to or creates a worktree with the name for the repo you are in',
|
||
|
|
term = cli.all {
|
||
|
|
name = cli.arg {
|
||
|
|
'name',
|
||
|
|
desc = 'Name of the worktree',
|
||
|
|
required = false,
|
||
|
|
},
|
||
|
|
list = cli.opt {
|
||
|
|
'--list', '-l',
|
||
|
|
desc = 'List existing worktrees for this repo',
|
||
|
|
flag = true,
|
||
|
|
},
|
||
|
|
root = cli.opt {
|
||
|
|
'--root', '-r',
|
||
|
|
desc = 'Return the root directory of the original repo',
|
||
|
|
flag = true,
|
||
|
|
},
|
||
|
|
}:and_then(function(args)
|
||
|
|
-- Handle special cases: "list" and "ls" as commands
|
||
|
|
local name = args.name
|
||
|
|
if name == "list" or name == "ls" then
|
||
|
|
args.list = true
|
||
|
|
args.name = nil
|
||
|
|
end
|
||
|
|
|
||
|
|
worktree_command({
|
||
|
|
name = args.name,
|
||
|
|
list = args.list,
|
||
|
|
root = args.root,
|
||
|
|
})
|
||
|
|
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())
|