Add clone and list commands
gtea clone <repo> or <owner/repo> — clones with auth baked in gtea list — shows all your repos with visibility and URL Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
51
cmd/list.go
Normal file
51
cmd/list.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
gogitea "code.gitea.io/sdk/gitea"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var listCmd = &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "List your Gitea repos",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
cfg, err := loadConfig()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
client, err := gogitea.NewClient(cfg.URL, gogitea.SetToken(cfg.Token))
|
||||
if err != nil {
|
||||
return fmt.Errorf("connecting to Gitea: %w", err)
|
||||
}
|
||||
|
||||
repos, _, err := client.ListMyRepos(gogitea.ListReposOptions{
|
||||
ListOptions: gogitea.ListOptions{PageSize: 50},
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("listing repos: %w", err)
|
||||
}
|
||||
|
||||
if len(repos) == 0 {
|
||||
fmt.Println("No repos found.")
|
||||
return nil
|
||||
}
|
||||
|
||||
fmt.Printf("%-30s %-8s %s\n", "NAME", "PRIVATE", "URL")
|
||||
fmt.Printf("%-30s %-8s %s\n", "----", "-------", "---")
|
||||
for _, r := range repos {
|
||||
priv := "public"
|
||||
if r.Private {
|
||||
priv = "private"
|
||||
}
|
||||
fmt.Printf("%-30s %-8s %s\n", r.Name, priv, r.HTMLURL)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(listCmd)
|
||||
}
|
||||
Reference in New Issue
Block a user