Files
gitea-tea/internal/app/label_export.go
T
bircni 2ba02cf915 feat(label): address labels by name and add import and clone
label edit bug and label delete kind/feature failed with "invalid resource
number", and label create took its name as --name and required
--color. Like gh, label create takes the name as an argument and picks
a random color without -c; label edit and delete take names or IDs
(delete several at once, after a confirmation that names them), and
-c/-d/-n/-f are the gh short flags. Without a name on a terminal, label
create asks for the name, color and description.

label list shows ID NAME COLOR DESCRIPTION FLAGS with a colored swatch
and exclusive and archived labels flagged. Mutations report ✓ lines.
label import reads a label file or stdin (label create --file still
works), label clone copies another repository's labels, skipping those
that exist unless --force, and label export writes to stdout by default
or to -O/--output.

Signed-off-by: bircni <bircni@icloud.com>
2026-10-12 00:16:09 +02:00

54 lines
1.6 KiB
Go

// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package app
import (
"io"
"strings"
"gitea.dev/tea/internal/terminal"
"github.com/spf13/cobra"
)
func (a *application) labelExportCommand(scope labelScope) *cobra.Command {
var output string
command := &cobra.Command{Use: "export", Short: "Export labels to a label file", Long: `Write every label as a row of a label file, the format tea label import reads, to standard
output or to a new file.`, Example: `$ tea label export > labels.txt
$ tea label export --org acme --output labels.txt
# Copy the labels of one repository to another
$ tea label export -R alice/old | tea label import - -R alice/new`, Args: argsExact(0), RunE: func(cmd *cobra.Command, _ []string) error {
if output != "" {
if err := validateDownloadDestination(output); err != nil {
return err
}
}
labels, err := scope(cmd)
if err != nil {
return err
}
return writeOutput(cmd, output, func(destination io.Writer) error {
items, err := labels.All(cmd.Context())
if err != nil {
return err
}
if a.options.json != "" {
return terminal.WriteJSON(destination, items, a.options.json, a.options.jq)
}
var text strings.Builder
for _, item := range items {
row, err := formatLabel(item)
if err != nil {
return err
}
text.WriteString(row)
}
_, err = io.WriteString(destination, text.String())
return err
})
}}
command.Flags().StringVarP(&output, "output", "O", "", "Write to a new `file` instead of standard output")
flagAliases(command, map[string]string{"output-file": "output"})
return command
}