-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
61 lines (52 loc) · 1.67 KB
/
main.go
File metadata and controls
61 lines (52 loc) · 1.67 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
package main
import (
"fmt"
"os"
"atlas.hash/internal/hash"
"atlas.hash/internal/ui"
tea "github.com/charmbracelet/bubbletea"
)
var Version = "dev"
func main() {
if len(os.Args) > 1 && (os.Args[1] == "-v" || os.Args[1] == "--version") {
fmt.Printf("atlas.hash v%s\n", Version)
return
}
if len(os.Args) > 1 && (os.Args[1] == "-h" || os.Args[1] == "--help" || os.Args[1] == "help") {
showHelp()
return
}
if len(os.Args) > 1 {
// Non-interactive mode
filePath := os.Args[1]
res, err := hash.Compute(filePath)
if err != nil {
fmt.Fprintf(os.Stderr, "Error computing hashes: %v\n", err)
os.Exit(1)
}
fmt.Printf("Target: %s\n\n", filePath)
fmt.Printf("%-10s %s\n", "MD5", res.MD5)
fmt.Printf("%-10s %s\n", "SHA1", res.SHA1)
fmt.Printf("%-10s %s\n", "SHA256", res.SHA256)
fmt.Printf("%-10s %s\n", "SHA512", res.SHA512)
return
}
// Interactive TUI Mode
p := tea.NewProgram(ui.NewModel(""))
if _, err := p.Run(); err != nil {
fmt.Fprintf(os.Stderr, "Error running program: %v\n", err)
os.Exit(1)
}
}
func showHelp() {
fmt.Println("Atlas Hash - A fast, minimalist hash utility for your terminal.")
fmt.Println("\nUsage:")
fmt.Println(" atlas.hash Start the interactive TUI to select a file")
fmt.Println(" atlas.hash <file> Compute and display hashes for the given file (non-interactive)")
fmt.Println(" atlas.hash -v, --version Show version information")
fmt.Println(" atlas.hash -h, --help Show this help information")
fmt.Println("\nTUI Controls:")
fmt.Println(" Type/Paste Enter file path or hash to compare")
fmt.Println(" Enter Confirm input")
fmt.Println(" Esc Quit the application")
}