Skip to content

Fix events CLI huh forms#176

Open
TheJolman wants to merge 9 commits intomainfrom
feat/events-cli
Open

Fix events CLI huh forms#176
TheJolman wants to merge 9 commits intomainfrom
feat/events-cli

Conversation

@TheJolman
Copy link
Collaborator

closes #151

@TheJolman TheJolman requested a review from GaballaGit as a code owner March 10, 2026 19:33
@TheJolman TheJolman marked this pull request as draft March 10, 2026 19:33
@github-actions
Copy link

github-actions bot commented Mar 10, 2026

godoc reference preview ready ✨
Go Documentation

@TheJolman TheJolman marked this pull request as ready for review March 10, 2026 19:38
@TheJolman TheJolman requested a review from Copilot March 12, 2026 19:42
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes the events CLI subcommand flow so commands like acmcsuf-cli events get execute directly instead of dropping into an interactive menu, aligning behavior with the pre-“huh forms” CLI.

Changes:

  • Replaces the interactive events menu with a standard events root command and direct subcommands.
  • Refactors events CRUD commands to use the shared internal/cli/client request helper + JSON pretty-printing.
  • Splits time-related helpers out of the removed utils/cli_helper.go into utils/time.go.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
internal/cli/root.go Adds a global /health connectivity check in PersistentPreRunE.
internal/cli/client/client.go Adds CheckConnection helper for health checks.
internal/cli/events/root.go Introduces a proper events root command and attaches subcommands.
internal/cli/events/get.go Simplifies get to run directly (optional --id).
internal/cli/events/delete.go Simplifies delete to require --id and run directly.
internal/cli/events/post.go Reworks post to use a huh form + shared HTTP client helper.
internal/cli/events/put.go Reworks put to require --id, fetch old payload, and submit updates via shared client helper.
internal/cli/events/events.go Removes the old interactive menu implementation.
utils/cli_helper.go Deletes the old CLI helper grab-bag file (printing/forms/connection/etc).
utils/time.go Adds time formatting + duration-to-end-time helper (moved from deleted helper file).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +83 to +92
huh.NewInput().
Title("Starts At\n"+
"Format: \x1b[93mMM/DD/YY HH:MM[PM | AM]\x1b[0m\n"+
"Leave empty to keep existing value").
Value(&startAtStr),
huh.NewInput().
Title("Ends At\n"+
"Format: \x1b[93mMM/DD/YY HH:MM[PM | AM]\x1b[0m\n"+
"Leave empty to keep existing value").
Value(&endAtStr),
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The form says "Leave empty to keep existing value" for Starts At/Ends At, but the existing timestamps are neither shown nor pre-filled, so users can't easily tell what value will be kept. Consider pre-populating these fields with the current value (formatted) or including the current value in the prompt text.

Copilot uses AI. Check for mistakes.
Comment on lines +10 to +14
// For unix times of int64 to readable format of 03:04:05PM 01/02/06
func FormatUnix(unixTime int64) string {
t := time.Unix(unixTime, 0)
return t.Format("01/02/06 03:04PM")
}
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FormatUnix's comment says the output includes seconds ("03:04:05PM"), but the layout string formats only hours/minutes ("03:04PM"). Update the comment or the format string so they match.

Copilot uses AI. Check for mistakes.
Comment on lines +19 to +25
// Since I cant go from 03:04:05 -> time.Time directly, I am left doing some... parsing
re := regexp.MustCompile(`(\d{2}):(\d{2})`)
parsedDuration := re.FindStringSubmatch(duration)

if parsedDuration == nil {
return -1, fmt.Errorf("error, duration time must be in the format: 03:04")
}
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TimeAfterDuration uses an unanchored regex (�d{2}):(�d{2}), so strings like "abc01:30xyz" will be accepted, and values like 99:99 will also parse without error. Consider anchoring the match (^...$) and validating hour/minute ranges before computing the duration.

Copilot uses AI. Check for mistakes.
return fmt.Errorf("failed to load config: %w", err)
}
return nil

Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rootCmd.PersistentPreRunE performs a /health check for every command invocation. This will also run for commands like config init and even --help, causing those commands to fail when the API server is down (or blocking on network). Consider skipping the health check for non-API commands (e.g., config, help, completion) or moving the connection check into only the command groups that actually talk to the API.

Suggested change
// Skip health check for commands that don't require API access
for c := cmd; c != nil; c = c.Parent() {
switch c.Name() {
case "config", "help", "completion":
return nil
}
}

Copilot uses AI. Check for mistakes.
Comment on lines +41 to +49
func CheckConnection(url string) error {
_, err := http.Get(url)
if err != nil {
// fang/lipgloss lowk nukes this custom formatting
return fmt.Errorf("\x1b[1;37;41mUNABLE TO CONNECT\x1b[0m | %s\n\t↳ %v",
"Did you forget to start the server?",
err)
}
return nil
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CheckConnection uses http.Get with the default client (no timeout). Since this is called during CLI startup now, a stalled network connection can hang the CLI indefinitely. Consider using an http.Client with a short timeout (and possibly HEAD instead of GET) to keep the CLI responsive.

Copilot uses AI. Check for mistakes.
PutEvents.Flags().BoolP("isallday", "a", false, "Set if new event is all day")

// This flag is neccessary
PutEvents.Flags().String("id", "", "Get an event by its id")
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The --id flag help text says "Get an event by its id", but this command is events put (update). Updating the flag description will make --help output accurate.

Suggested change
PutEvents.Flags().String("id", "", "Get an event by its id")
PutEvents.Flags().String("id", "", "ID of the event to update")

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Command line subcommands broken after huh forms merged

2 participants