···2233import (
44 "context"
55+ "errors"
56 "os"
77+ "runtime"
6879 "github.com/charmbracelet/fang"
1010+ "github.com/charmbracelet/lipgloss/v2"
811 "github.com/spf13/cobra"
1212+ "gopkg.in/ini.v1"
913)
10141115func main() {
1616+ // init our cobra command with a name and description
1217 cmd := &cobra.Command{
1318 Use: "akami",
1419 Short: "🌷 the cutsie hackatime helper",
1520 }
1616- if err := fang.Execute(context.TODO(), cmd); err != nil {
2121+2222+ // add our lipgloss styles
2323+ fancy := lipgloss.NewStyle().Foreground(lipgloss.Magenta).Bold(true).Italic(true)
2424+ muted := lipgloss.NewStyle().Foreground(lipgloss.BrightBlue).Italic(true)
2525+2626+ // root diagnose command
2727+ cmd.AddCommand(&cobra.Command{
2828+ Use: "doc",
2929+ Short: "diagnose potential hackatime issues",
3030+ RunE: func(c *cobra.Command, _ []string) error {
3131+ // check our os
3232+ os_name := runtime.GOOS
3333+3434+ user_dir, err := os.UserHomeDir()
3535+ if err != nil {
3636+ 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")
3737+ }
3838+ hackatime_path := user_dir + "/.wakatime.cfg"
3939+4040+ switch os_name {
4141+ case "linux":
4242+ case "darwin":
4343+ case "windows":
4444+ default:
4545+ 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?")
4646+ }
4747+4848+ c.Println("Looks like you are running", fancy.Render(os_name), "so lets take a look at", muted.Render(hackatime_path), "for your config")
4949+5050+ rawCfg, err := os.ReadFile(hackatime_path)
5151+ if errors.Is(err, os.ErrNotExist) {
5252+ 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")
5353+ }
5454+5555+ cfg, err := ini.Load(rawCfg)
5656+ if err != nil {
5757+ return errors.New(err.Error())
5858+ }
5959+6060+ settings, err := cfg.GetSection("settings")
6161+ if err != nil {
6262+ 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())
6363+ }
6464+6565+ api_key := settings.Key("api_key").String()
6666+ api_url := settings.Key("api_url").String()
6767+ if api_key == "" {
6868+ 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?")
6969+ }
7070+ if api_url == "" {
7171+ 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?")
7272+ }
7373+7474+ if api_url != "https://hackatime.hackclub.com/api/hackatime/v1" {
7575+ 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")
7676+ }
7777+7878+ return nil
7979+ },
8080+ })
8181+8282+ // this is where we get the fancy fang magic ✨
8383+ if err := fang.Execute(
8484+ context.Background(),
8585+ cmd,
8686+ ); err != nil {
1787 os.Exit(1)
1888 }
1989}