Merge branch 'no-branch-p2'
This commit is contained in:
commit
7f2119753d
32
src/cli.ts
32
src/cli.ts
|
|
@ -18,23 +18,33 @@ program.name("sandlot").description("Branch-based development with git worktrees
|
|||
|
||||
// ── sandlot new <branch> ──────────────────────────────────────────────
|
||||
|
||||
program
|
||||
.command("new")
|
||||
.argument("<branch>", "branch name or prompt (if it contains spaces)")
|
||||
.argument("[prompt]", "initial prompt for Claude")
|
||||
.option("-p, --print <prompt>", "run Claude in non-interactive mode with -p")
|
||||
.description("Create a new session and launch Claude")
|
||||
.action(async (branch: string, prompt: string | undefined, opts: { print?: string }) => {
|
||||
// If the "branch" contains spaces, it's actually a prompt — derive the branch name
|
||||
if (branch.includes(" ")) {
|
||||
prompt = branch
|
||||
branch = branch
|
||||
function branchFromPrompt(text: string): string {
|
||||
return text
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9\s-]/g, "")
|
||||
.trim()
|
||||
.replace(/\s+/g, "-")
|
||||
.slice(0, 20)
|
||||
.replace(/-$/, "")
|
||||
}
|
||||
|
||||
program
|
||||
.command("new")
|
||||
.argument("[branch]", "branch name or prompt (if it contains spaces)")
|
||||
.argument("[prompt]", "initial prompt for Claude")
|
||||
.option("-p, --print <prompt>", "run Claude in non-interactive mode with -p")
|
||||
.description("Create a new session and launch Claude")
|
||||
.action(async (branch: string | undefined, prompt: string | undefined, opts: { print?: string }) => {
|
||||
// No branch given — derive from -p prompt
|
||||
if (!branch && opts.print) {
|
||||
branch = branchFromPrompt(opts.print)
|
||||
} else if (!branch) {
|
||||
console.error("Branch name or prompt is required.")
|
||||
process.exit(1)
|
||||
} else if (branch.includes(" ")) {
|
||||
// If the "branch" contains spaces, it's actually a prompt — derive the branch name
|
||||
prompt = branch
|
||||
branch = branchFromPrompt(branch)
|
||||
}
|
||||
const root = await git.repoRoot()
|
||||
const worktreeAbs = join(homedir(), '.sandlot', basename(root), branch)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user