repotool/main.lua

134 lines
4.4 KiB
Lua
Raw Normal View History

2025-07-01 00:56:36 +00:00
-- 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")
2025-07-01 01:23:13 +00:00
local worktree = require("worktree")
2025-07-01 00:56:36 +00:00
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),
},
2025-07-01 01:23:13 +00:00
-- Worktree command with subcommands
2025-07-01 00:56:36 +00:00
cli.cmd {
'worktree', 'w', 'wt',
2025-07-01 01:23:13 +00:00
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),
2025-07-01 00:56:36 +00:00
},
2025-07-01 01:23:13 +00:00
-- 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),
2025-07-01 00:56:36 +00:00
},
2025-07-01 01:23:13 +00:00
-- 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),
2025-07-01 00:56:36 +00:00
},
2025-07-01 01:23:13 +00:00
-- 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),
},
},
2025-07-01 00:56:36 +00:00
},
-- 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())