-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelp.go
More file actions
121 lines (100 loc) · 4.61 KB
/
help.go
File metadata and controls
121 lines (100 loc) · 4.61 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
MIT License
Copyright (c) 2026 Jan Van Herck (https://github.com/jvherck)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/*
This file contains the logic for rendering the command-line help menu. It uses lipgloss for styling the output to
provide a clean and readable experience.
*/
package main
import (
"fmt"
"os"
"strings"
"github.com/charmbracelet/lipgloss"
)
// commands lists the available positional commands and their descriptions.
var commands = [][]string{
{"help", "Shows this help menu"},
{"version", "Shows the version of Git Janitor"},
{"update", "Update Git Janitor to the latest version"},
}
// flags lists the available CLI flags and their descriptions.
var flags = [][]string{
{"-h, --help", "Shows this help menu"},
{"-v, --version", "Shows the version of Git Janitor"},
{"--dry-run", "Simulate deletion without actually removing branches"},
{"--protect", "Comma-separated list of branches to protect, supports * wildcards (e.g. 'qa,release-*')"},
{"--stale-days", "Number of days before a branch is considered stale (default 30)"},
}
// keyBindings lists the TUI interactive keybindings and their functions.
var keyBindings = [][]string{
{"↑ / k", "Move cursor up"},
{"↓ / j", "Move cursor down"},
{"Space", "Toggle selection for the current branch"},
{"a", "Select ALL unprotected branches"},
{"m", "Select MERGED branches (those already merged into the default branch)"},
{"g", "Select GONE branches (those whose upstream remote branch was deleted)"},
{"s", "Select STALE branches (no commits within the stale-days threshold)"},
{"c", "CLEAR all current selections"},
{"o", "Cycle through sort orders (Alphabetical, Latest Commits, Oldest Commits)"},
{"Enter", "Proceed to deletion confirmation screen"},
{"q / Ctrl+C", "Quit the application"},
}
// printHelp constructs and renders a styled help menu to standard output,
// then exits the application successfully.
func printHelp() {
var sb strings.Builder
titleStyle := lipgloss.NewStyle().Foreground(lipgloss.Color(ColorTitle)).Bold(true)
sb.WriteString(titleStyle.Render("🧹 Git Janitor") + "\n\n")
descStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("252"))
sb.WriteString(descStyle.Render("A fast, interactive TUI for cleaning up local Git branches.") + "\n\n")
headingStyle := lipgloss.NewStyle().Foreground(lipgloss.Color(ColorPrimary)).Bold(true).Underline(true)
keyColumnStyle := lipgloss.NewStyle().Foreground(lipgloss.Color(ColorSuccess)).Width(18)
// Usage section
sb.WriteString(headingStyle.Render("USAGE:") + "\n")
sb.WriteString(" git-janitor [command] [flags]\n\n")
// Commands section
sb.WriteString(headingStyle.Render("COMMANDS:") + "\n")
for _, row := range commands {
sb.WriteString(fmt.Sprintf(" %s %s\n", keyColumnStyle.Render(row[0]), row[1]))
}
// Flags section
sb.WriteString("\n" + headingStyle.Render("FLAGS:") + "\n")
for _, row := range flags {
sb.WriteString(fmt.Sprintf(" %s %s\n", keyColumnStyle.Render(row[0]), row[1]))
}
// Keybindings section
sb.WriteString("\n" + headingStyle.Render("INTERACTIVE KEYBINDINGS:") + "\n")
for _, row := range keyBindings {
sb.WriteString(fmt.Sprintf(" %s %s\n", keyColumnStyle.Render(row[0]), row[1]))
}
// Examples section for better clarity
sb.WriteString("\n" + headingStyle.Render("EXAMPLES:") + "\n")
sb.WriteString(" git-janitor update\n")
sb.WriteString(" git-janitor --dry-run\n")
sb.WriteString(" git-janitor --protect \"production,release-*\"\n")
sb.WriteString(" git-janitor --stale-days 14\n")
helpBox := lipgloss.NewStyle().
Border(lipgloss.RoundedBorder()).
BorderForeground(lipgloss.Color(ColorSecondary)).
Padding(1, 4).
Render(sb.String())
fmt.Println(helpBox)
os.Exit(0)
}