🌷 the cutsie hackatime helper

feat: add basic config file troubleshooting and parsing

dunkirk.sh 137700a0 0322f9ff

verified
+96 -4
+8 -3
go.mod
··· 3 3 go 1.24.3 4 4 5 5 require ( 6 - github.com/charmbracelet/colorprofile v0.3.0 // indirect 6 + github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect 7 + github.com/charmbracelet/colorprofile v0.3.1 // indirect 7 8 github.com/charmbracelet/fang v0.1.0 // indirect 9 + github.com/charmbracelet/lipgloss v1.1.0 // indirect 8 10 github.com/charmbracelet/lipgloss/v2 v2.0.0-beta.1 // indirect 9 - github.com/charmbracelet/x/ansi v0.8.0 // indirect 11 + github.com/charmbracelet/x/ansi v0.9.3 // indirect 10 12 github.com/charmbracelet/x/cellbuf v0.0.13 // indirect 11 13 github.com/charmbracelet/x/exp/charmtone v0.0.0-20250603201427-c31516f43444 // indirect 12 14 github.com/charmbracelet/x/term v0.2.1 // indirect 13 15 github.com/inconshreveable/mousetrap v1.1.0 // indirect 14 16 github.com/lucasb-eyer/go-colorful v1.2.0 // indirect 17 + github.com/mattn/go-isatty v0.0.20 // indirect 15 18 github.com/mattn/go-runewidth v0.0.16 // indirect 16 19 github.com/muesli/cancelreader v0.2.2 // indirect 17 20 github.com/muesli/mango v0.1.0 // indirect 18 21 github.com/muesli/mango-cobra v1.2.0 // indirect 19 22 github.com/muesli/mango-pflag v0.1.0 // indirect 20 23 github.com/muesli/roff v0.1.0 // indirect 24 + github.com/muesli/termenv v0.16.0 // indirect 21 25 github.com/rivo/uniseg v0.4.7 // indirect 22 26 github.com/spf13/cobra v1.9.1 // indirect 23 27 github.com/spf13/pflag v1.0.6 // indirect 24 28 github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect 25 - golang.org/x/sys v0.31.0 // indirect 29 + golang.org/x/sys v0.33.0 // indirect 26 30 golang.org/x/text v0.24.0 // indirect 31 + gopkg.in/ini.v1 v1.67.0 // indirect 27 32 )
+17
go.sum
··· 1 + github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k= 2 + github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= 1 3 github.com/charmbracelet/colorprofile v0.3.0 h1:KtLh9uuu1RCt+Hml4s6Hz+kB1PfV3wi++1h5ia65yKQ= 2 4 github.com/charmbracelet/colorprofile v0.3.0/go.mod h1:oHJ340RS2nmG1zRGPmhJKJ/jf4FPNNk0P39/wBPA1G0= 5 + github.com/charmbracelet/colorprofile v0.3.1 h1:k8dTHMd7fgw4bnFd7jXTLZrSU/CQrKnL3m+AxCzDz40= 6 + github.com/charmbracelet/colorprofile v0.3.1/go.mod h1:/GkGusxNs8VB/RSOh3fu0TJmQ4ICMMPApIIVn0KszZ0= 3 7 github.com/charmbracelet/fang v0.1.0 h1:SlZS2crf3/zQh7Mr4+W+7QR1k+L08rrPX5rm5z3d7Wg= 4 8 github.com/charmbracelet/fang v0.1.0/go.mod h1:Zl/zeUQ8EtQuGyiV0ZKZlZPDowKRTzu8s/367EpN/fc= 9 + github.com/charmbracelet/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoFqR/noCY= 10 + github.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30= 5 11 github.com/charmbracelet/lipgloss/v2 v2.0.0-beta.1 h1:D9AJJuYTN5pvz6mpIGO1ijLKpfTYSHOtKGgwoTQ4Gog= 6 12 github.com/charmbracelet/lipgloss/v2 v2.0.0-beta.1/go.mod h1:tRlx/Hu0lo/j9viunCN2H+Ze6JrmdjQlXUQvvArgaOc= 7 13 github.com/charmbracelet/x/ansi v0.8.0 h1:9GTq3xq9caJW8ZrBTe0LIe2fvfLR/bYXKTx2llXn7xE= 8 14 github.com/charmbracelet/x/ansi v0.8.0/go.mod h1:wdYl/ONOLHLIVmQaxbIYEC/cRKOQyjTkowiI4blgS9Q= 15 + github.com/charmbracelet/x/ansi v0.9.3 h1:BXt5DHS/MKF+LjuK4huWrC6NCvHtexww7dMayh6GXd0= 16 + github.com/charmbracelet/x/ansi v0.9.3/go.mod h1:3RQDQ6lDnROptfpWuUVIUG64bD2g2BgntdxH0Ya5TeE= 9 17 github.com/charmbracelet/x/cellbuf v0.0.13 h1:/KBBKHuVRbq1lYx5BzEHBAFBP8VcQzJejZ/IA3iR28k= 10 18 github.com/charmbracelet/x/cellbuf v0.0.13/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs= 11 19 github.com/charmbracelet/x/exp/charmtone v0.0.0-20250603201427-c31516f43444 h1:IJDiTgVE56gkAGfq0lBEloWgkXMk4hl/bmuPoicI4R0= ··· 17 25 github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= 18 26 github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= 19 27 github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= 28 + github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= 29 + github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= 20 30 github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc= 21 31 github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= 22 32 github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA= ··· 29 39 github.com/muesli/mango-pflag v0.1.0/go.mod h1:YEQomTxaCUp8PrbhFh10UfbhbQrM/xJ4i2PB8VTLLW0= 30 40 github.com/muesli/roff v0.1.0 h1:YD0lalCotmYuF5HhZliKWlIx7IEhiXeSfq7hNjFqGF8= 31 41 github.com/muesli/roff v0.1.0/go.mod h1:pjAHQM9hdUUwm/krAfrLGgJkXJ+YuhtsfZ42kieB2Ig= 42 + github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc= 43 + github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk= 32 44 github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= 33 45 github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= 34 46 github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= ··· 39 51 github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= 40 52 github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no= 41 53 github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM= 54 + golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 42 55 golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik= 43 56 golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= 57 + golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= 58 + golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= 44 59 golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0= 45 60 golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU= 46 61 gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 62 + gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= 63 + gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= 47 64 gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+71 -1
main.go
··· 2 2 3 3 import ( 4 4 "context" 5 + "errors" 5 6 "os" 7 + "runtime" 6 8 7 9 "github.com/charmbracelet/fang" 10 + "github.com/charmbracelet/lipgloss/v2" 8 11 "github.com/spf13/cobra" 12 + "gopkg.in/ini.v1" 9 13 ) 10 14 11 15 func main() { 16 + // init our cobra command with a name and description 12 17 cmd := &cobra.Command{ 13 18 Use: "akami", 14 19 Short: "🌷 the cutsie hackatime helper", 15 20 } 16 - if err := fang.Execute(context.TODO(), cmd); err != nil { 21 + 22 + // add our lipgloss styles 23 + fancy := lipgloss.NewStyle().Foreground(lipgloss.Magenta).Bold(true).Italic(true) 24 + muted := lipgloss.NewStyle().Foreground(lipgloss.BrightBlue).Italic(true) 25 + 26 + // root diagnose command 27 + cmd.AddCommand(&cobra.Command{ 28 + Use: "doc", 29 + Short: "diagnose potential hackatime issues", 30 + RunE: func(c *cobra.Command, _ []string) error { 31 + // check our os 32 + os_name := runtime.GOOS 33 + 34 + user_dir, err := os.UserHomeDir() 35 + if err != nil { 36 + return errors.New("somehow your user doesn't exist? fairly sure this should never happen; plz report this to @krn on slack or via email at me@dunkirk.sh") 37 + } 38 + hackatime_path := user_dir + "/.wakatime.cfg" 39 + 40 + switch os_name { 41 + case "linux": 42 + case "darwin": 43 + case "windows": 44 + default: 45 + return errors.New("hmm you don't seem to be running a recognized os? you are listed as running " + fancy.Render(os_name) + "; can you plz report this to @krn on slack or via email at me@dunkirk.sh?") 46 + } 47 + 48 + c.Println("Looks like you are running", fancy.Render(os_name), "so lets take a look at", muted.Render(hackatime_path), "for your config") 49 + 50 + rawCfg, err := os.ReadFile(hackatime_path) 51 + if errors.Is(err, os.ErrNotExist) { 52 + return errors.New("you don't have a wakatime config file! go check https://hackatime.hackclub.com/my/wakatime_setup for the instructions and then try this again") 53 + } 54 + 55 + cfg, err := ini.Load(rawCfg) 56 + if err != nil { 57 + return errors.New(err.Error()) 58 + } 59 + 60 + settings, err := cfg.GetSection("settings") 61 + if err != nil { 62 + return errors.New("wow! your config file seems to be messed up and doesn't have a settings heading; can you follow the instructions at https://hackatime.hackclub.com/my/wakatime_setup to regenerate it?\n\nThe raw error we got was: " + err.Error()) 63 + } 64 + 65 + api_key := settings.Key("api_key").String() 66 + api_url := settings.Key("api_url").String() 67 + if api_key == "" { 68 + return errors.New("hmm 🤔 looks like you don't have an api_key in your config file? are you sure you have followed the setup instructions at https://hackatime.hackclub.com/my/wakatime_setup correctly?") 69 + } 70 + if api_url == "" { 71 + return errors.New("hmm 🤔 looks like you don't have an api_url in your config file? are you sure you have followed the setup instructions at https://hackatime.hackclub.com/my/wakatime_setup correctly?") 72 + } 73 + 74 + if api_url != "https://hackatime.hackclub.com/api/hackatime/v1" { 75 + c.Println("\nYour api url", muted.Render(api_url), "doesn't match the expected url of", muted.Render("https://hackatime.hackclub.com/api/hackatime/v1"), "however if you are using a custom forwarder or are sure you know what you are doing then you are probably fine") 76 + } 77 + 78 + return nil 79 + }, 80 + }) 81 + 82 + // this is where we get the fancy fang magic ✨ 83 + if err := fang.Execute( 84 + context.Background(), 85 + cmd, 86 + ); err != nil { 17 87 os.Exit(1) 18 88 } 19 89 }