feat: add json output for list and view commands
This commit is contained in:
parent
fe23f2fce3
commit
3ccef4e1c6
5 changed files with 192 additions and 52 deletions
|
|
@ -72,8 +72,10 @@ func init() {
|
|||
releaseListCmd.Flags().Bool("draft", false, "Filter by draft status")
|
||||
releaseListCmd.Flags().Bool("prerelease", false, "Filter by prerelease status")
|
||||
releaseListCmd.Flags().Int("limit", 30, "Maximum number of releases to fetch")
|
||||
releaseListCmd.Flags().Bool("json", false, "Output releases as JSON")
|
||||
|
||||
releaseViewCmd.Flags().StringP("repo", "R", "", "Repository in owner/name format")
|
||||
releaseViewCmd.Flags().Bool("json", false, "Output release as JSON")
|
||||
|
||||
releaseCreateCmd.Flags().StringP("repo", "R", "", "Repository in owner/name format")
|
||||
releaseCreateCmd.Flags().StringP("title", "t", "", "Release title (defaults to tag)")
|
||||
|
|
@ -146,6 +148,10 @@ func runReleaseList(cmd *cobra.Command, args []string) error {
|
|||
releases = releases[:limit]
|
||||
}
|
||||
|
||||
if jsonOutput, _ := cmd.Flags().GetBool("json"); jsonOutput {
|
||||
return writeJSON(releases)
|
||||
}
|
||||
|
||||
if len(releases) == 0 {
|
||||
fmt.Printf("No releases in %s/%s\n", owner, name)
|
||||
return nil
|
||||
|
|
@ -186,6 +192,22 @@ func runReleaseView(cmd *cobra.Command, args []string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
attachments, err := listReleaseAttachments(client, owner, name, release.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if jsonOutput, _ := cmd.Flags().GetBool("json"); jsonOutput {
|
||||
payload := struct {
|
||||
Release *gitea.Release `json:"release"`
|
||||
Assets []*gitea.Attachment `json:"assets,omitempty"`
|
||||
}{
|
||||
Release: release,
|
||||
Assets: attachments,
|
||||
}
|
||||
return writeJSON(payload)
|
||||
}
|
||||
|
||||
fmt.Printf("Release %s\n", release.TagName)
|
||||
fmt.Printf("Title: %s\n", release.Title)
|
||||
fmt.Printf("Type: %s\n", releaseType(release))
|
||||
|
|
@ -206,10 +228,6 @@ func runReleaseView(cmd *cobra.Command, args []string) error {
|
|||
fmt.Printf("\n%s\n", release.Note)
|
||||
}
|
||||
|
||||
attachments, err := listReleaseAttachments(client, owner, name, release.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(attachments) > 0 {
|
||||
fmt.Printf("\nAssets (%d):\n", len(attachments))
|
||||
for _, asset := range attachments {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue