commands

package
v1.9.3-0...-199195a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 21, 2026 License: MIT Imports: 44 Imported by: 0

README

commands

import "github.com/tagoro9/fotingo/pkg/commands"

Package commands wires Cobra commands and delegates command workflows to internal modules.

Package commands provides the CLI commands for fotingo.

This file defines JSON output structures for all commands to support machine-readable output via the --json flag.

Index

Variables

Build metadata injected at release time via ldflags.

var (
    Version   = "dev"
    GitCommit = "unknown"
    BuildTime = "unknown"
    Platform  = "unknown/unknown"
)

var Fotingo = &cobra.Command{
    Use:           "fotingo",
    Short:         i18n.T(i18n.RootShort),
    Long:          i18n.T(i18n.RootLong),
    SilenceUsage:  true,
    SilenceErrors: true,
}

Global holds the current global flags

var Global = GlobalFlags{}

func Execute

func Execute()

Execute runs the root command and handles exit codes. This is the main entry point for the CLI and should be called from main().

func ExecuteWithExitCode

func ExecuteWithExitCode() (exitCode int)

ExecuteWithExitCode runs the root command and returns the exit code. This is useful for testing where os.Exit should not be called.

func IsShellCompletionRequest

func IsShellCompletionRequest() bool

func OutputJSON

func OutputJSON(data interface{})

OutputJSON outputs the data as formatted JSON to stdout. This is a convenience function that creates a new JSONOutput and writes.

func OutputJSONError

func OutputJSONError(err error)

OutputJSONError outputs an error as JSON to stdout.

func ShouldOutputDebug

func ShouldOutputDebug() bool

ShouldOutputDebug returns true when diagnostic output should be shown.

func ShouldOutputJSON

func ShouldOutputJSON() bool

ShouldOutputJSON returns true if the --json flag is set. Commands should check this before outputting human-readable text.

func ShouldOutputVerbose

func ShouldOutputVerbose() bool

ShouldOutputVerbose returns true when step-level progress should be shown.

func ShouldSuppressOutput

func ShouldSuppressOutput() bool

ShouldSuppressOutput returns true if output should be suppressed. This is true when --quiet is set or when --json is set (to avoid mixing human-readable output with JSON).

type AISetupOutput

AISetupOutput represents JSON output for `fotingo ai setup`.

type AISetupOutput struct {
    Success   bool            `json:"success"`
    Scope     string          `json:"scope,omitempty"`
    Providers []string        `json:"providers,omitempty"`
    DryRun    bool            `json:"dryRun,omitempty"`
    Force     bool            `json:"force,omitempty"`
    Results   []AISetupResult `json:"results,omitempty"`
    Error     string          `json:"error,omitempty"`
}

type AISetupResult

AISetupResult captures one provider install outcome.

type AISetupResult struct {
    Provider string `json:"provider"`
    Scope    string `json:"scope"`
    Root     string `json:"root"`
    Path     string `json:"path"`
    Status   string `json:"status"`
    Reason   string `json:"reason,omitempty"`
}

type BranchInfo

BranchInfo contains information about a git branch

type BranchInfo struct {
    Name          string `json:"name"`
    IssueID       string `json:"issueId,omitempty"`
    DefaultBranch string `json:"defaultBranch,omitempty"`
}

type CommitInfo

CommitInfo contains information about a git commit

type CommitInfo struct {
    Hash    string `json:"hash"`
    Message string `json:"message"`
    Author  string `json:"author"`
}

type ErrorOutput

ErrorOutput represents a JSON error response.

Example:

{
  "error": "failed to create branch",
  "code": 4,
  "type": "Git error"
}
type ErrorOutput struct {
    Error string `json:"error"`
    Code  int    `json:"code,omitempty"`
    Type  string `json:"type,omitempty"`
}

type GlobalFlags

GlobalFlags holds the global flags available to all commands

type GlobalFlags struct {
    Branch  string
    Yes     bool
    JSON    bool
    Quiet   bool
    Verbose bool
    Debug   bool
    NoColor bool
}

type InspectOutput

InspectOutput represents the JSON output of the inspect command

type InspectOutput struct {
    Branch   *BranchInfo  `json:"branch,omitempty"`
    Issue    *IssueInfo   `json:"issue,omitempty"`
    IssueIDs []string     `json:"issueIds,omitempty"`
    Commits  []CommitInfo `json:"commits,omitempty"`
}

type IssueInfo

IssueInfo contains information about a Jira issue

type IssueInfo struct {
    Key         string `json:"key"`
    Summary     string `json:"summary"`
    Description string `json:"description,omitempty"`
    Status      string `json:"status"`
    Type        string `json:"type"`
    ParentKey   string `json:"parentKey,omitempty"`
    EpicKey     string `json:"epicKey,omitempty"`
    URL         string `json:"url"`
}

type JSONOutput

JSONOutput provides utilities for outputting JSON responses.

type JSONOutput struct {
    // contains filtered or unexported fields
}

func NewJSONOutput
func NewJSONOutput() *JSONOutput

NewJSONOutput creates a new JSONOutput that writes to stdout.

func (*JSONOutput) Write
func (j *JSONOutput) Write(data interface{}) error

Write outputs data as formatted JSON to stdout.

func (*JSONOutput) WriteError
func (j *JSONOutput) WriteError(err error) error

WriteError outputs an error as JSON.

func (*JSONOutput) WriteSuccess
func (j *JSONOutput) WriteSuccess(data interface{}) error

WriteSuccess outputs a generic success response.

type OpenOutput

OpenOutput represents the JSON output of the open command.

Example success output:

{
  "success": true,
  "target": "pr",
  "url": "https://github.com/owner/repo/pull/42",
  "opened": true
}
type OpenOutput struct {
    Success bool   `json:"success"`
    Target  string `json:"target"`
    URL     string `json:"url,omitempty"`
    Opened  bool   `json:"opened,omitempty"`
    Error   string `json:"error,omitempty"`
}

type PullRequestInfo

PullRequestInfo contains information about a GitHub pull request.

type PullRequestInfo struct {
    Number int    `json:"number"`
    URL    string `json:"url"`
    Title  string `json:"title"`
    Draft  bool   `json:"draft"`
    State  string `json:"state"`
}

type ReviewOutput

ReviewOutput represents the JSON output of the review command.

Example success output:

{
  "success": true,
  "pullRequest": {
    "number": 42,
    "url": "https://github.com/owner/repo/pull/42",
    "title": "[PROJ-123] Fix login bug",
    "draft": false,
    "state": "open"
  },
  "issue": {
    "key": "PROJ-123",
    "summary": "Fix login bug",
    "status": "In Review",
    "type": "Bug",
    "url": "https://jira.example.com/browse/PROJ-123"
  },
  "labels": ["bug", "priority"],
  "reviewers": ["alice", "bob"],
  "teamReviewers": ["acme/platform"],
  "assignees": ["alice"]
}

Example when PR already exists:

{
  "success": true,
  "pullRequest": {
    "number": 42,
    "url": "https://github.com/owner/repo/pull/42",
    "title": "[PROJ-123] Fix login bug",
    "draft": false,
    "state": "open"
  },
  "existed": true
}
type ReviewOutput struct {
    Success       bool             `json:"success"`
    PullRequest   *PullRequestInfo `json:"pullRequest,omitempty"`
    Issue         *IssueInfo       `json:"issue,omitempty"`
    Labels        []string         `json:"labels,omitempty"`
    Reviewers     []string         `json:"reviewers,omitempty"`
    TeamReviewers []string         `json:"teamReviewers,omitempty"`
    Assignees     []string         `json:"assignees,omitempty"`
    Existed       bool             `json:"existed,omitempty"`
    Error         string           `json:"error,omitempty"`
}

type SearchOutput

SearchOutput represents the JSON output of the search command.

type SearchOutput struct {
    Success bool               `json:"success"`
    Domain  string             `json:"domain"`
    Query   string             `json:"query"`
    Results []SearchResultInfo `json:"results"`
    Error   string             `json:"error,omitempty"`
}

type SearchResultInfo

SearchResultInfo contains one resolved review metadata search result.

type SearchResultInfo struct {
    Resolved string `json:"resolved"`
    Label    string `json:"label"`
    Detail   string `json:"detail,omitempty"`
    Kind     string `json:"kind,omitempty"`
}

type StartBranchInfo

StartBranchInfo contains branch information for the start command output.

type StartBranchInfo struct {
    Name    string `json:"name"`
    Created bool   `json:"created"`
}

type StartOutput

StartOutput represents the JSON output of the start command.

Example success output:

{
  "success": true,
  "issue": {
    "key": "PROJ-123",
    "summary": "Fix login bug",
    "status": "In Progress",
    "type": "Bug",
    "url": "https://jira.example.com/browse/PROJ-123"
  },
  "branch": {
    "name": "feature/PROJ-123-fix-login-bug",
    "created": true
  }
}

Example error output:

{
  "success": false,
  "error": "failed to initialize Jira client: authentication required"
}
type StartOutput struct {
    Success bool             `json:"success"`
    Issue   *IssueInfo       `json:"issue,omitempty"`
    Branch  *StartBranchInfo `json:"branch,omitempty"`
    Error   string           `json:"error,omitempty"`
}

Generated by gomarkdoc

Documentation

Overview

Package commands wires Cobra commands and delegates command workflows to internal modules.

Package commands provides the CLI commands for fotingo.

This file defines JSON output structures for all commands to support machine-readable output via the --json flag.

Index

Constants

This section is empty.

Variables

View Source
var (
	Version   = "dev"
	GitCommit = "unknown"
	BuildTime = "unknown"
	Platform  = "unknown/unknown"
)

Build metadata injected at release time via ldflags.

View Source
var Fotingo = &cobra.Command{
	Use:           "fotingo",
	Short:         i18n.T(i18n.RootShort),
	Long:          i18n.T(i18n.RootLong),
	SilenceUsage:  true,
	SilenceErrors: true,
}
View Source
var Global = GlobalFlags{}

Global holds the current global flags

Functions

func Execute

func Execute()

Execute runs the root command and handles exit codes. This is the main entry point for the CLI and should be called from main().

func ExecuteWithExitCode

func ExecuteWithExitCode() (exitCode int)

ExecuteWithExitCode runs the root command and returns the exit code. This is useful for testing where os.Exit should not be called.

func IsShellCompletionRequest

func IsShellCompletionRequest() bool

func OutputJSON

func OutputJSON(data interface{})

OutputJSON outputs the data as formatted JSON to stdout. This is a convenience function that creates a new JSONOutput and writes.

func OutputJSONError

func OutputJSONError(err error)

OutputJSONError outputs an error as JSON to stdout.

func ShouldOutputDebug

func ShouldOutputDebug() bool

ShouldOutputDebug returns true when diagnostic output should be shown.

func ShouldOutputJSON

func ShouldOutputJSON() bool

ShouldOutputJSON returns true if the --json flag is set. Commands should check this before outputting human-readable text.

func ShouldOutputVerbose

func ShouldOutputVerbose() bool

ShouldOutputVerbose returns true when step-level progress should be shown.

func ShouldSuppressOutput

func ShouldSuppressOutput() bool

ShouldSuppressOutput returns true if output should be suppressed. This is true when --quiet is set or when --json is set (to avoid mixing human-readable output with JSON).

Types

type AISetupOutput

type AISetupOutput struct {
	Success   bool            `json:"success"`
	Scope     string          `json:"scope,omitempty"`
	Providers []string        `json:"providers,omitempty"`
	DryRun    bool            `json:"dryRun,omitempty"`
	Force     bool            `json:"force,omitempty"`
	Results   []AISetupResult `json:"results,omitempty"`
	Error     string          `json:"error,omitempty"`
}

AISetupOutput represents JSON output for `fotingo ai setup`.

type AISetupResult

type AISetupResult struct {
	Provider string `json:"provider"`
	Scope    string `json:"scope"`
	Root     string `json:"root"`
	Path     string `json:"path"`
	Status   string `json:"status"`
	Reason   string `json:"reason,omitempty"`
}

AISetupResult captures one provider install outcome.

type BranchInfo

type BranchInfo struct {
	Name          string `json:"name"`
	IssueID       string `json:"issueId,omitempty"`
	DefaultBranch string `json:"defaultBranch,omitempty"`
}

BranchInfo contains information about a git branch

type CommitInfo

type CommitInfo struct {
	Hash    string `json:"hash"`
	Message string `json:"message"`
	Author  string `json:"author"`
}

CommitInfo contains information about a git commit

type ErrorOutput

type ErrorOutput struct {
	Error string `json:"error"`
	Code  int    `json:"code,omitempty"`
	Type  string `json:"type,omitempty"`
}

ErrorOutput represents a JSON error response.

Example:

{
  "error": "failed to create branch",
  "code": 4,
  "type": "Git error"
}

type GlobalFlags

type GlobalFlags struct {
	Branch  string
	Yes     bool
	JSON    bool
	Quiet   bool
	Verbose bool
	Debug   bool
	NoColor bool
}

GlobalFlags holds the global flags available to all commands

type InspectOutput

type InspectOutput struct {
	Branch   *BranchInfo  `json:"branch,omitempty"`
	Issue    *IssueInfo   `json:"issue,omitempty"`
	IssueIDs []string     `json:"issueIds,omitempty"`
	Commits  []CommitInfo `json:"commits,omitempty"`
}

InspectOutput represents the JSON output of the inspect command

type IssueInfo

type IssueInfo struct {
	Key         string `json:"key"`
	Summary     string `json:"summary"`
	Description string `json:"description,omitempty"`
	Status      string `json:"status"`
	Type        string `json:"type"`
	ParentKey   string `json:"parentKey,omitempty"`
	EpicKey     string `json:"epicKey,omitempty"`
	URL         string `json:"url"`
}

IssueInfo contains information about a Jira issue

type JSONOutput

type JSONOutput struct {
	// contains filtered or unexported fields
}

JSONOutput provides utilities for outputting JSON responses.

func NewJSONOutput

func NewJSONOutput() *JSONOutput

NewJSONOutput creates a new JSONOutput that writes to stdout.

func (*JSONOutput) Write

func (j *JSONOutput) Write(data interface{}) error

Write outputs data as formatted JSON to stdout.

func (*JSONOutput) WriteError

func (j *JSONOutput) WriteError(err error) error

WriteError outputs an error as JSON.

func (*JSONOutput) WriteSuccess

func (j *JSONOutput) WriteSuccess(data interface{}) error

WriteSuccess outputs a generic success response.

type OpenOutput

type OpenOutput struct {
	Success bool   `json:"success"`
	Target  string `json:"target"`
	URL     string `json:"url,omitempty"`
	Opened  bool   `json:"opened,omitempty"`
	Error   string `json:"error,omitempty"`
}

OpenOutput represents the JSON output of the open command.

Example success output:

{
  "success": true,
  "target": "pr",
  "url": "https://github.com/owner/repo/pull/42",
  "opened": true
}

type PullRequestInfo

type PullRequestInfo struct {
	Number int    `json:"number"`
	URL    string `json:"url"`
	Title  string `json:"title"`
	Draft  bool   `json:"draft"`
	State  string `json:"state"`
}

PullRequestInfo contains information about a GitHub pull request.

type ReviewOutput

type ReviewOutput struct {
	Success       bool             `json:"success"`
	PullRequest   *PullRequestInfo `json:"pullRequest,omitempty"`
	Issue         *IssueInfo       `json:"issue,omitempty"`
	Labels        []string         `json:"labels,omitempty"`
	Reviewers     []string         `json:"reviewers,omitempty"`
	TeamReviewers []string         `json:"teamReviewers,omitempty"`
	Assignees     []string         `json:"assignees,omitempty"`
	Existed       bool             `json:"existed,omitempty"`
	Error         string           `json:"error,omitempty"`
}

ReviewOutput represents the JSON output of the review command.

Example success output:

{
  "success": true,
  "pullRequest": {
    "number": 42,
    "url": "https://github.com/owner/repo/pull/42",
    "title": "[PROJ-123] Fix login bug",
    "draft": false,
    "state": "open"
  },
  "issue": {
    "key": "PROJ-123",
    "summary": "Fix login bug",
    "status": "In Review",
    "type": "Bug",
    "url": "https://jira.example.com/browse/PROJ-123"
  },
  "labels": ["bug", "priority"],
  "reviewers": ["alice", "bob"],
  "teamReviewers": ["acme/platform"],
  "assignees": ["alice"]
}

Example when PR already exists:

{
  "success": true,
  "pullRequest": {
    "number": 42,
    "url": "https://github.com/owner/repo/pull/42",
    "title": "[PROJ-123] Fix login bug",
    "draft": false,
    "state": "open"
  },
  "existed": true
}

type SearchOutput

type SearchOutput struct {
	Success bool               `json:"success"`
	Domain  string             `json:"domain"`
	Query   string             `json:"query"`
	Results []SearchResultInfo `json:"results"`
	Error   string             `json:"error,omitempty"`
}

SearchOutput represents the JSON output of the search command.

type SearchResultInfo

type SearchResultInfo struct {
	Resolved string `json:"resolved"`
	Label    string `json:"label"`
	Detail   string `json:"detail,omitempty"`
	Kind     string `json:"kind,omitempty"`
}

SearchResultInfo contains one resolved review metadata search result.

type StartBranchInfo

type StartBranchInfo struct {
	Name    string `json:"name"`
	Created bool   `json:"created"`
}

StartBranchInfo contains branch information for the start command output.

type StartOutput

type StartOutput struct {
	Success bool             `json:"success"`
	Issue   *IssueInfo       `json:"issue,omitempty"`
	Branch  *StartBranchInfo `json:"branch,omitempty"`
	Error   string           `json:"error,omitempty"`
}

StartOutput represents the JSON output of the start command.

Example success output:

{
  "success": true,
  "issue": {
    "key": "PROJ-123",
    "summary": "Fix login bug",
    "status": "In Progress",
    "type": "Bug",
    "url": "https://jira.example.com/browse/PROJ-123"
  },
  "branch": {
    "name": "feature/PROJ-123-fix-login-bug",
    "created": true
  }
}

Example error output:

{
  "success": false,
  "error": "failed to initialize Jira client: authentication required"
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL