Initial commit: gtea CLI tool

Go CLI that wraps the Gitea API and git to create repos, commit,
push, and pull without leaving the terminal.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-17 14:11:34 -04:00
commit b7ea167786
11 changed files with 404 additions and 0 deletions

50
cmd/config.go Normal file
View File

@@ -0,0 +1,50 @@
package cmd
import (
"bufio"
"fmt"
"os"
"strings"
"github.com/spf13/cobra"
)
var configCmd = &cobra.Command{
Use: "config",
Short: "Set your Gitea URL, username, and API token",
RunE: func(cmd *cobra.Command, args []string) error {
reader := bufio.NewReader(os.Stdin)
cfg := &Config{}
if existing, err := loadConfig(); err == nil {
*cfg = *existing
}
cfg.URL = prompt(reader, fmt.Sprintf("Gitea URL [%s]", cfg.URL), cfg.URL)
cfg.Username = prompt(reader, fmt.Sprintf("Username [%s]", cfg.Username), cfg.Username)
cfg.Token = prompt(reader, fmt.Sprintf("API Token [%s]", maskToken(cfg.Token)), cfg.Token)
if err := saveConfig(cfg); err != nil {
return fmt.Errorf("saving config: %w", err)
}
fmt.Println("Config saved to", configPath())
return nil
},
}
func prompt(reader *bufio.Reader, label, fallback string) string {
fmt.Printf("%s: ", label)
input, _ := reader.ReadString('\n')
input = strings.TrimSpace(input)
if input == "" {
return fallback
}
return input
}
func maskToken(t string) string {
if len(t) < 4 {
return "****"
}
return t[:4] + "****"
}