Skip to content

feat: add ability to get command information from *State #4

Description

@mfridman

I currently handle retrieving flags (or env variables) from my application. I am able to print out something like:

error: must provide --dir flag or set DIR environment variable

However, it'd be nice if the command name could be printed so the error looks something like this (notice the extra command information):

error: command "goose status": must provide --dir flag or set DIR environment variable

This is currently not possible because path []*Command is unexported on the *State, and that object is the only thing available in Exec functions. We should consider exporting it, or adding a method to retrieve either the full command path or just the terminal command.

Activity

  1. mfridman commented on Feb 16, 2026

    @mfridman
    CollaboratorAuthor

    One solution could be to expose what's needed, but I'm not yet sure how much from the *Command is needed?

    // CommandPath returns the full command path as a space-separated string, e.g., "goose status".
    func (s *State) CommandPath() string {
      return getCommandPath(s.path)
    }
    
    // CommandName returns the name of the terminal (current) command being executed.
    func (s *State) CommandName() string {
      if len(s.path) == 0 {
        return ""
      }
      return s.path[len(s.path)-1].Name
    }
  2. added theissue type on Feb 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions