this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

CLI usage improvements, and crypto private key gen helper (#463)

I only recently discovered the `ArgsUsage` field in urfave/cli command
config. It helps a lot!

authored by

Whyrusleeping and committed by
GitHub
f3cd044e 474c6afa

+108 -29
+56
atproto/crypto/cmd/atp-crypto/main.go
··· 1 + package main 2 + 3 + import ( 4 + "fmt" 5 + "log/slog" 6 + "os" 7 + 8 + "github.com/bluesky-social/indigo/atproto/crypto" 9 + 10 + "github.com/urfave/cli/v2" 11 + ) 12 + 13 + func main() { 14 + app := cli.App{ 15 + Name: "atp-crypto", 16 + Usage: "informal debugging CLI tool for atproto key and cryptography", 17 + } 18 + app.Commands = []*cli.Command{ 19 + &cli.Command{ 20 + Name: "generate", 21 + Usage: "create a new private key", 22 + Flags: []cli.Flag{ 23 + &cli.BoolFlag{ 24 + Name: "p256", 25 + Usage: "generate a P-256 / secp256r1 / ES256 private key (default)", 26 + }, 27 + &cli.BoolFlag{ 28 + Name: "k256", 29 + Usage: "generate a K-256 / secp256k1 / ES256K private key", 30 + }, 31 + }, 32 + 33 + Action: runGenerate, 34 + }, 35 + } 36 + h := slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelDebug}) 37 + slog.SetDefault(slog.New(h)) 38 + app.RunAndExitOnError() 39 + } 40 + 41 + func runGenerate(cctx *cli.Context) error { 42 + if cctx.Bool("k256") { 43 + priv, err := crypto.GeneratePrivateKeyK256() 44 + if err != nil { 45 + return err 46 + } 47 + fmt.Println(priv.Multibase()) 48 + } else { 49 + priv, err := crypto.GeneratePrivateKeyP256() 50 + if err != nil { 51 + return err 52 + } 53 + fmt.Println(priv.Multibase()) 54 + } 55 + return nil 56 + }
+2
atproto/crypto/keys.go
··· 29 29 // The encoding format is curve-specific, and is generally "compact" for private keys. 30 30 // No ASN.1 or other enclosing structure is applied to the bytes. 31 31 Bytes() []byte 32 + 33 + // NOTE: should Multibase() (string, error) be part of this interface? Probably. 32 34 } 33 35 34 36 // Common interface for all the supported atproto cryptographic systems.
+12 -9
atproto/identity/cmd/atp-id/main.go
··· 20 20 } 21 21 app.Commands = []*cli.Command{ 22 22 &cli.Command{ 23 - Name: "lookup", 24 - Usage: "fully resolve an at-identifier (DID or handle)", 25 - Action: runLookup, 23 + Name: "lookup", 24 + Usage: "fully resolve an at-identifier (DID or handle)", 25 + ArgsUsage: "<at-identifier>", 26 + Action: runLookup, 26 27 }, 27 28 &cli.Command{ 28 - Name: "resolve-handle", 29 - Usage: "resolve a handle to DID", 30 - Action: runResolveHandle, 29 + Name: "resolve-handle", 30 + Usage: "resolve a handle to DID", 31 + ArgsUsage: "<handle>", 32 + Action: runResolveHandle, 31 33 }, 32 34 &cli.Command{ 33 - Name: "resolve-did", 34 - Usage: "resolve a DID to DID Document", 35 - Action: runResolveDID, 35 + Name: "resolve-did", 36 + Usage: "resolve a DID to DID Document", 37 + ArgsUsage: "<did>", 38 + Action: runResolveDID, 36 39 }, 37 40 } 38 41 h := slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelDebug})
+1 -1
atproto/identity/did.go
··· 123 123 return nil, ErrDIDNotFound 124 124 } 125 125 if resp.StatusCode != http.StatusOK { 126 - return nil, fmt.Errorf("failed did:web well-known fetch, HTTP status: %d", resp.StatusCode) 126 + return nil, fmt.Errorf("failed did:plc resolution, HTTP status: %d", resp.StatusCode) 127 127 } 128 128 129 129 var doc DIDDocument
+4 -3
atproto/syntax/cmd/atp-syntax/main.go
··· 17 17 } 18 18 app.Commands = []*cli.Command{ 19 19 &cli.Command{ 20 - Name: "parse-tid", 21 - Usage: "parse a TID and output timestamp", 22 - Action: runParseTID, 20 + Name: "parse-tid", 21 + Usage: "parse a TID and output timestamp", 22 + ArgsUsage: "<tid>", 23 + Action: runParseTID, 23 24 }, 24 25 } 25 26 h := slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelDebug})
+3 -1
cmd/gosky/account.go
··· 191 191 } 192 192 193 193 var deleteAccountCmd = &cli.Command{ 194 - Name: "delete", 194 + Name: "delete", 195 + Usage: "permanently delete account", 196 + ArgsUsage: "<token> <password>", 195 197 Action: func(cctx *cli.Context) error { 196 198 xrpcc, err := cliutil.GetXrpcClient(cctx, false) 197 199 if err != nil {
+10 -6
cmd/gosky/admin.go
··· 44 44 Name: "check-user", 45 45 Flags: []cli.Flag{ 46 46 &cli.BoolFlag{ 47 - Name: "raw", 47 + Name: "raw", 48 + Usage: "dump simple JSON response to stdout", 48 49 }, 49 50 &cli.BoolFlag{ 50 51 Name: "list-invited-dids", 51 52 }, 52 53 }, 53 - ArgsUsage: `[handle]`, 54 + ArgsUsage: `<did-or-handle>`, 54 55 Action: func(cctx *cli.Context) error { 55 56 xrpcc, err := cliutil.GetXrpcClient(cctx, false) 56 57 if err != nil { ··· 398 399 } 399 400 400 401 var disableInvitesCmd = &cli.Command{ 401 - Name: "disable-invites", 402 + Name: "disable-invites", 403 + ArgsUsage: "<did-or-handle>", 402 404 Action: func(cctx *cli.Context) error { 403 405 404 406 xrpcc, err := cliutil.GetXrpcClient(cctx, false) ··· 439 441 } 440 442 441 443 var enableInvitesCmd = &cli.Command{ 442 - Name: "enable-invites", 444 + Name: "enable-invites", 445 + ArgsUsage: "<did-or-handle>", 443 446 Action: func(cctx *cli.Context) error { 444 447 445 448 xrpcc, err := cliutil.GetXrpcClient(cctx, false) ··· 489 492 Usage: "print account email for each DID", 490 493 }, 491 494 }, 492 - ArgsUsage: `[handle]`, 495 + ArgsUsage: `<did-or-handle>`, 493 496 Action: func(cctx *cli.Context) error { 494 497 xrpcc, err := cliutil.GetXrpcClient(cctx, false) 495 498 if err != nil { ··· 647 650 } 648 651 649 652 var queryModerationStatusesCmd = &cli.Command{ 650 - Name: "query-moderation-statuses", 653 + Name: "query-moderation-statuses", 654 + ArgsUsage: "<did-or-handle>", 651 655 Action: func(cctx *cli.Context) error { 652 656 653 657 xrpcc, err := cliutil.GetXrpcClient(cctx, false)
+16 -7
cmd/gosky/bgs.go
··· 78 78 } 79 79 80 80 var bgsKickConnectionCmd = &cli.Command{ 81 - Name: "kick", 81 + Name: "kick", 82 + Usage: "tell Relay/BGS to drop the subscription connection", 83 + ArgsUsage: "<host>", 82 84 Flags: []cli.Flag{ 83 85 &cli.BoolFlag{ 84 - Name: "ban", 86 + Name: "ban", 87 + Usage: "make the disconnect sticky", 85 88 }, 86 89 }, 87 90 Action: func(cctx *cli.Context) error { ··· 166 169 } 167 170 168 171 var bgsBanDomainCmd = &cli.Command{ 169 - Name: "ban-domain", 172 + Name: "ban-domain", 173 + ArgsUsage: "<domain>", 170 174 Action: func(cctx *cli.Context) error { 171 175 url := cctx.String("bgs") + "/admin/subs/banDomain" 172 176 ··· 213 217 } 214 218 215 219 var bgsTakedownRepoCmd = &cli.Command{ 216 - Name: "take-down-repo", 220 + Name: "take-down-repo", 221 + ArgsUsage: "<did>", 217 222 Action: func(cctx *cli.Context) error { 218 223 url := cctx.String("bgs") + "/admin/repo/takeDown" 219 224 ··· 260 265 } 261 266 262 267 var bgsSetNewSubsEnabledCmd = &cli.Command{ 263 - Name: "set-accept-subs", 268 + Name: "set-accept-subs", 269 + ArgsUsage: "<boolean>", 270 + Usage: "set configuration for whether new subscriptions are allowed", 264 271 Action: func(cctx *cli.Context) error { 265 272 url := cctx.String("bgs") + "/admin/subs/setEnabled" 266 273 ··· 305 312 } 306 313 307 314 var bgsCompactRepo = &cli.Command{ 308 - Name: "compact-repo", 315 + Name: "compact-repo", 316 + ArgsUsage: "<did>", 309 317 Flags: []cli.Flag{ 310 318 &cli.BoolFlag{ 311 319 Name: "fast", ··· 427 435 } 428 436 429 437 var bgsResetRepo = &cli.Command{ 430 - Name: "reset-repo", 438 + Name: "reset-repo", 439 + ArgsUsage: "<did>", 431 440 Action: func(cctx *cli.Context) error { 432 441 url := cctx.String("bgs") + "/admin/repo/reset" 433 442
+4 -2
cmd/gosky/debug.go
··· 461 461 } 462 462 463 463 var debugFeedGenCmd = &cli.Command{ 464 - Name: "debug-feed", 464 + Name: "debug-feed", 465 + ArgsUsage: "<at-uri>", 465 466 Action: func(cctx *cli.Context) error { 466 467 xrpcc, err := cliutil.GetXrpcClient(cctx, true) 467 468 if err != nil { ··· 592 593 }, 593 594 } 594 595 var debugFeedViewCmd = &cli.Command{ 595 - Name: "view-feed", 596 + Name: "view-feed", 597 + Usage: "<at-uri>", 596 598 Action: func(cctx *cli.Context) error { 597 599 xrpcc, err := cliutil.GetXrpcClient(cctx, true) 598 600 if err != nil {