Set module to git.abrell.se/victor/mydev so it installs from the private Gitea host, and add an MIT LICENSE. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
80 lines
1.6 KiB
Go
80 lines
1.6 KiB
Go
package cmd
|
||
|
||
import (
|
||
"context"
|
||
"fmt"
|
||
"os"
|
||
"text/tabwriter"
|
||
|
||
"git.abrell.se/victor/mydev/internal/checks"
|
||
"git.abrell.se/victor/mydev/internal/config"
|
||
|
||
"github.com/spf13/cobra"
|
||
)
|
||
|
||
var statusCmd = &cobra.Command{
|
||
Use: "status",
|
||
Short: "One-shot overview: AWS auth + docker + repos",
|
||
Run: func(cmd *cobra.Command, args []string) {
|
||
cfg, err := config.Load()
|
||
if err != nil {
|
||
fmt.Fprintln(os.Stderr, err)
|
||
os.Exit(1)
|
||
}
|
||
ctx := context.Background()
|
||
|
||
// AWS
|
||
if awsmfa, err := cfg.AWSMFA(); err != nil {
|
||
fmt.Printf("AWS – %s\n", err)
|
||
} else {
|
||
a := checks.AWSAuth(ctx, awsmfa)
|
||
switch {
|
||
case a.Authed:
|
||
fmt.Printf("AWS ✓ authed %s\n", a.Detail)
|
||
case a.Err != "":
|
||
fmt.Printf("AWS ✗ awsmfa error: %s\n", a.Err)
|
||
default:
|
||
fmt.Printf("AWS ✗ re-auth needed — run 'mydev auth login'\n")
|
||
}
|
||
}
|
||
|
||
// Docker
|
||
cs, derr := checks.Containers(ctx)
|
||
if derr != "" {
|
||
fmt.Printf("DOCKER ✗ %s\n", derr)
|
||
} else {
|
||
running := 0
|
||
for _, c := range cs {
|
||
if c.State == "running" {
|
||
running++
|
||
}
|
||
}
|
||
fmt.Printf("DOCKER %d running / %d total\n", running, len(cs))
|
||
}
|
||
|
||
// Repos
|
||
rs, rerr := checks.ReposMulti(ctx, cfg.ReposRoots)
|
||
if rerr != "" {
|
||
fmt.Printf("REPOS ✗ %s\n", rerr)
|
||
} else {
|
||
fmt.Println("REPOS")
|
||
w := tabwriter.NewWriter(os.Stdout, 0, 2, 2, ' ', 0)
|
||
for _, r := range rs {
|
||
flag := "clean"
|
||
if r.Dirty {
|
||
flag = "dirty"
|
||
}
|
||
if r.Err != "" {
|
||
flag = "err: " + r.Err
|
||
}
|
||
fmt.Fprintf(w, " %s\t%s\t%s\n", r.Name, r.Branch, flag)
|
||
}
|
||
w.Flush()
|
||
}
|
||
},
|
||
}
|
||
|
||
func init() {
|
||
rootCmd.AddCommand(statusCmd)
|
||
}
|