feat: add branch, notification, org, open, whoami commands
Ports five commands from tea that fgj-sid was missing:
- fgj branch {list,rename,delete} — list branches with protection
status, rename, and delete with confirmation.
- fgj notification {list,read} — list user notifications (unread by
default, --all for everything), mark individual threads read.
- fgj org {list,create,delete} — manage organizations on the host.
Create accepts --description/--full-name/--website/--location and
--visibility (public/limited/private).
- fgj open [number] — open the repo, issue, or PR in a browser.
Auto-detects issue-vs-PR via GetIssue. Falls back to printing the
URL when stdout is not a TTY or --url is passed.
- fgj whoami — display authenticated user + host.
All commands follow the established pattern (parseRepo + config.Load +
api.NewClientFromConfig + ios), support --json where list semantics
apply, and share a new loadClient helper for host-scoped (non-repo)
commands. Tested live against forgejo.zerova.net.
Refs audit recommendation.md §'v0.5.0 — Missing resources'.
This commit is contained in:
parent
d4b5b79541
commit
17ca49d0c5
5 changed files with 665 additions and 0 deletions
53
cmd/whoami.go
Normal file
53
cmd/whoami.go
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var whoamiCmd = &cobra.Command{
|
||||
Use: "whoami",
|
||||
Short: "Show the authenticated user on the current host",
|
||||
Long: "Display login, full name, and email for the authenticated user on the active host.",
|
||||
Example: ` # Show who you are on the active host
|
||||
fgj whoami
|
||||
|
||||
# On a specific host
|
||||
fgj whoami --hostname forgejo.example.com
|
||||
|
||||
# As JSON
|
||||
fgj whoami --json`,
|
||||
RunE: runWhoami,
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(whoamiCmd)
|
||||
addJSONFlags(whoamiCmd, "Output as JSON")
|
||||
}
|
||||
|
||||
func runWhoami(cmd *cobra.Command, args []string) error {
|
||||
client, err := loadClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
user, _, err := client.GetMyUserInfo()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to fetch current user: %w", err)
|
||||
}
|
||||
|
||||
if wantJSON(cmd) {
|
||||
return outputJSON(cmd, user)
|
||||
}
|
||||
|
||||
fmt.Fprintf(ios.Out, "%s\n", user.UserName)
|
||||
if user.FullName != "" && user.FullName != user.UserName {
|
||||
fmt.Fprintf(ios.Out, " name: %s\n", user.FullName)
|
||||
}
|
||||
if user.Email != "" {
|
||||
fmt.Fprintf(ios.Out, " email: %s\n", user.Email)
|
||||
}
|
||||
fmt.Fprintf(ios.Out, " host: %s\n", client.Hostname())
|
||||
return nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue