-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
85 lines (68 loc) · 2.33 KB
/
Copy pathProgram.cs
File metadata and controls
85 lines (68 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System.CommandLine;
var branchArg = new Argument<string>("branch-name")
{
Description = "Name of the branch/worktree to create",
Arity = ArgumentArity.ZeroOrOne
};
var listOption = new Option<bool>("--list", "-l")
{
Description = "List all worktrees with branch and upstream info"
};
var pruneOption = new Option<bool>("--prune", "-p")
{
Description = "Remove worktrees whose upstream branch is gone and delete empty parent directories"
};
var removeOption = new Option<string>("--remove", "-r")
{
Description = "Remove a worktree and its local branch"
};
var setupOption = new Option<string>("--setup", "-s")
{
Description = "Clone a repository into a bare worktree layout: <name>/.bare + default branch worktree"
};
var forceOption = new Option<bool>("--force", "-f")
{
Description = "Force remove worktrees with dirty/untracked changes and force delete local branches (use with --prune or --remove)"
};
var colorOption = new Option<bool>("--color")
{
Description = "Force colored output even when piped"
};
var noColorOption = new Option<bool>("--no-color")
{
Description = "Disable colored output"
};
var rootCommand = new RootCommand("Creates a worktree for the given branch, automatically tracking an existing remote branch or creating a new local branch.")
{
branchArg,
listOption,
pruneOption,
removeOption,
setupOption,
forceOption,
colorOption,
noColorOption
};
rootCommand.SetAction(parseResult =>
{
Output.Init(parseResult.GetValue(colorOption), parseResult.GetValue(noColorOption));
var setupUrl = parseResult.GetValue(setupOption);
if (!string.IsNullOrEmpty(setupUrl))
return Commands.Setup(setupUrl);
if (parseResult.GetValue(listOption))
return Commands.List();
var force = parseResult.GetValue(forceOption);
if (parseResult.GetValue(pruneOption))
return Commands.Prune(force);
var removeBranch = parseResult.GetValue(removeOption);
if (!string.IsNullOrEmpty(removeBranch))
return Commands.Remove(removeBranch, force);
var branchName = parseResult.GetValue(branchArg);
if (string.IsNullOrEmpty(branchName))
{
Console.Error.WriteLine("Error: branch name is required. Use -h for help.");
return 1;
}
return Commands.Create(branchName);
});
return rootCommand.Parse(args).Invoke();