this repo has no description
0
fork

Configure Feed

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

update atproto cmd examples to urfave/cli/v3

+104 -91
+20 -22
atproto/atclient/cmd/atp-client-demo/main.go
··· 12 12 "github.com/bluesky-social/indigo/atproto/identity" 13 13 "github.com/bluesky-social/indigo/atproto/syntax" 14 14 15 - "github.com/urfave/cli/v2" 15 + "github.com/urfave/cli/v3" 16 16 ) 17 17 18 18 func main() { 19 - app := cli.App{ 19 + app := cli.Command{ 20 20 Name: "atp-client-demo", 21 21 Usage: "dev helper for atproto/client SDK", 22 22 Commands: []*cli.Command{ ··· 117 117 } 118 118 h := slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelDebug}) 119 119 slog.SetDefault(slog.New(h)) 120 - app.RunAndExitOnError() 120 + if err := app.Run(context.Background(), os.Args); err != nil { 121 + slog.Error("command failed", "error", err) 122 + os.Exit(-1) 123 + } 121 124 } 122 125 123 126 func getFeed(ctx context.Context, c *atclient.APIClient) error { ··· 156 159 return nil 157 160 } 158 161 159 - func runGetFeedPublic(cctx *cli.Context) error { 160 - ctx := cctx.Context 162 + func runGetFeedPublic(ctx context.Context, cmd *cli.Command) error { 161 163 162 164 c := atclient.APIClient{ 163 - Host: cctx.String("host"), 165 + Host: cmd.String("host"), 164 166 } 165 167 166 168 return getFeed(ctx, &c) 167 169 } 168 170 169 - func runListRecordsPublic(cctx *cli.Context) error { 170 - ctx := cctx.Context 171 + func runListRecordsPublic(ctx context.Context, cmd *cli.Command) error { 171 172 172 173 c := atclient.APIClient{ 173 - Host: cctx.String("host"), 174 + Host: cmd.String("host"), 174 175 } 175 176 176 177 return listRecords(ctx, &c) 177 178 } 178 179 179 - func runLoginAuth(cctx *cli.Context) error { 180 - ctx := cctx.Context 180 + func runLoginAuth(ctx context.Context, cmd *cli.Command) error { 181 181 182 - atid, err := syntax.ParseAtIdentifier(cctx.String("username")) 182 + atid, err := syntax.ParseAtIdentifier(cmd.String("username")) 183 183 if err != nil { 184 184 return err 185 185 } 186 186 187 187 dir := identity.DefaultDirectory() 188 188 189 - c, err := atclient.LoginWithPassword(ctx, dir, *atid, cctx.String("password"), "", nil) 189 + c, err := atclient.LoginWithPassword(ctx, dir, *atid, cmd.String("password"), "", nil) 190 190 if err != nil { 191 191 return err 192 192 } ··· 205 205 return nil 206 206 } 207 207 208 - func runGetFeedAuth(cctx *cli.Context) error { 209 - ctx := cctx.Context 208 + func runGetFeedAuth(ctx context.Context, cmd *cli.Command) error { 210 209 211 - atid, err := syntax.ParseAtIdentifier(cctx.String("username")) 210 + atid, err := syntax.ParseAtIdentifier(cmd.String("username")) 212 211 if err != nil { 213 212 return err 214 213 } 215 214 216 215 dir := identity.DefaultDirectory() 217 216 218 - c, err := atclient.LoginWithPassword(ctx, dir, *atid, cctx.String("password"), "", nil) 217 + c, err := atclient.LoginWithPassword(ctx, dir, *atid, cmd.String("password"), "", nil) 219 218 if err != nil { 220 219 return err 221 220 } 222 - c = c.WithService(cctx.String("appview")) 221 + c = c.WithService(cmd.String("appview")) 223 222 224 223 return getFeed(ctx, c) 225 224 } 226 225 227 - func runLookupAdmin(cctx *cli.Context) error { 228 - ctx := cctx.Context 226 + func runLookupAdmin(ctx context.Context, cmd *cli.Command) error { 229 227 230 - c := atclient.NewAdminClient(cctx.String("host"), cctx.String("admin-password")) 228 + c := atclient.NewAdminClient(cmd.String("host"), cmd.String("admin-password")) 231 229 232 230 var d json.RawMessage 233 231 params := map[string]any{ 234 - "did": cctx.String("did"), 232 + "did": cmd.String("did"), 235 233 } 236 234 if err := c.Get(ctx, "com.atproto.admin.getAccountInfo", params, &d); err != nil { 237 235 return err
+9 -5
atproto/atcrypto/cmd/atp-crypto/main.go
··· 1 1 package main 2 2 3 3 import ( 4 + "context" 4 5 "fmt" 5 6 "log/slog" 6 7 "os" 7 8 8 9 "github.com/bluesky-social/indigo/atproto/atcrypto" 9 10 10 - "github.com/urfave/cli/v2" 11 + "github.com/urfave/cli/v3" 11 12 ) 12 13 13 14 func main() { 14 - app := cli.App{ 15 + app := cli.Command{ 15 16 Name: "atp-crypto", 16 17 Usage: "informal debugging CLI tool for atproto key and cryptography", 17 18 } ··· 35 36 } 36 37 h := slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelDebug}) 37 38 slog.SetDefault(slog.New(h)) 38 - app.RunAndExitOnError() 39 + if err := app.Run(context.Background(), os.Args); err != nil { 40 + slog.Error("command failed", "error", err) 41 + os.Exit(-1) 42 + } 39 43 } 40 44 41 - func runGenerate(cctx *cli.Context) error { 42 - if cctx.Bool("k256") { 45 + func runGenerate(ctx context.Context, cmd *cli.Command) error { 46 + if cmd.Bool("k256") { 43 47 priv, err := atcrypto.GeneratePrivateKeyK256() 44 48 if err != nil { 45 49 return err
+18 -14
atproto/auth/oauth/cmd/oauth-web-demo/main.go
··· 1 1 package main 2 2 3 3 import ( 4 - _ "embed" 4 + "context" 5 5 "encoding/json" 6 6 "fmt" 7 7 "html/template" ··· 10 10 "os" 11 11 "slices" 12 12 13 + _ "embed" 13 14 _ "github.com/joho/godotenv/autoload" 14 15 15 16 "github.com/bluesky-social/indigo/atproto/atcrypto" ··· 18 19 "github.com/bluesky-social/indigo/atproto/syntax" 19 20 20 21 "github.com/gorilla/sessions" 21 - "github.com/urfave/cli/v2" 22 + "github.com/urfave/cli/v3" 22 23 ) 23 24 24 25 func main() { 25 - app := cli.App{ 26 + app := cli.Command{ 26 27 Name: "oauth-web-demo", 27 28 Usage: "atproto OAuth web server demo", 28 29 Action: runServer, ··· 31 32 Name: "session-secret", 32 33 Usage: "random string/token used for session cookie security", 33 34 Required: true, 34 - EnvVars: []string{"SESSION_SECRET"}, 35 + Sources: cli.EnvVars("SESSION_SECRET"), 35 36 }, 36 37 &cli.StringFlag{ 37 38 Name: "hostname", 38 39 Usage: "public host name for this client (if not localhost dev mode)", 39 - EnvVars: []string{"CLIENT_HOSTNAME"}, 40 + Sources: cli.EnvVars("CLIENT_HOSTNAME"), 40 41 }, 41 42 &cli.StringFlag{ 42 43 Name: "client-secret-key", 43 44 Usage: "confidential client secret key. should be P-256 private key in multibase encoding", 44 - EnvVars: []string{"CLIENT_SECRET_KEY"}, 45 + Sources: cli.EnvVars("CLIENT_SECRET_KEY"), 45 46 }, 46 47 &cli.StringFlag{ 47 48 Name: "client-secret-key-id", 48 49 Usage: "key id for client-secret-key", 49 50 Value: "primary", 50 - EnvVars: []string{"CLIENT_SECRET_KEY_ID"}, 51 + Sources: cli.EnvVars("CLIENT_SECRET_KEY_ID"), 51 52 }, 52 53 }, 53 54 } 54 55 h := slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelDebug}) 55 56 slog.SetDefault(slog.New(h)) 56 - app.RunAndExitOnError() 57 + if err := app.Run(context.Background(), os.Args); err != nil { 58 + slog.Error("command failed", "error", err) 59 + os.Exit(-1) 60 + } 57 61 } 58 62 59 63 type Server struct { ··· 77 81 var tmplPostText string 78 82 var tmplPost = template.Must(template.Must(template.New("post.html").Parse(tmplBaseText)).Parse(tmplPostText)) 79 83 80 - func runServer(cctx *cli.Context) error { 84 + func runServer(ctx context.Context, cmd *cli.Command) error { 81 85 82 86 // the 'account:email' scope is requested only as a demo of users not granting a permission during auth flow 83 87 scopes := []string{"atproto", "repo:app.bsky.feed.post?action=create", "account:email"} 84 88 bind := ":8080" 85 89 86 90 var config oauth.ClientConfig 87 - hostname := cctx.String("hostname") 91 + hostname := cmd.String("hostname") 88 92 if hostname == "" { 89 93 config = oauth.NewLocalhostConfig( 90 94 fmt.Sprintf("http://127.0.0.1%s/oauth/callback", bind), ··· 100 104 } 101 105 102 106 // If a client secret key is provided (as a multibase string), turn this in to a confidential client 103 - if cctx.String("client-secret-key") != "" && hostname != "" { 104 - priv, err := atcrypto.ParsePrivateMultibase(cctx.String("client-secret-key")) 107 + if cmd.String("client-secret-key") != "" && hostname != "" { 108 + priv, err := atcrypto.ParsePrivateMultibase(cmd.String("client-secret-key")) 105 109 if err != nil { 106 110 return err 107 111 } 108 - if err := config.SetClientSecret(priv, cctx.String("client-secret-key-id")); err != nil { 112 + if err := config.SetClientSecret(priv, cmd.String("client-secret-key-id")); err != nil { 109 113 return err 110 114 } 111 115 slog.Info("configuring confidential OAuth client") ··· 114 118 oauthClient := oauth.NewClientApp(&config, oauth.NewMemStore()) 115 119 116 120 srv := Server{ 117 - CookieStore: sessions.NewCookieStore([]byte(cctx.String("session-secret"))), 121 + CookieStore: sessions.NewCookieStore([]byte(cmd.String("session-secret"))), 118 122 Dir: identity.DefaultDirectory(), 119 123 OAuth: oauthClient, 120 124 }
+12 -12
atproto/identity/cmd/atp-id/main.go
··· 10 10 "github.com/bluesky-social/indigo/atproto/identity" 11 11 "github.com/bluesky-social/indigo/atproto/syntax" 12 12 13 - "github.com/urfave/cli/v2" 13 + "github.com/urfave/cli/v3" 14 14 ) 15 15 16 16 func main() { 17 - app := cli.App{ 17 + app := cli.Command{ 18 18 Name: "atp-id", 19 19 Usage: "informal debugging CLI tool for atproto identities", 20 20 } ··· 40 40 } 41 41 h := slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelDebug}) 42 42 slog.SetDefault(slog.New(h)) 43 - app.RunAndExitOnError() 43 + if err := app.Run(context.Background(), os.Args); err != nil { 44 + slog.Error("command failed", "error", err) 45 + os.Exit(-1) 46 + } 44 47 } 45 48 46 - func runLookup(cctx *cli.Context) error { 47 - ctx := context.Background() 48 - s := cctx.Args().First() 49 + func runLookup(ctx context.Context, cmd *cli.Command) error { 50 + s := cmd.Args().First() 49 51 if s == "" { 50 52 return fmt.Errorf("need to provide identifier as an argument") 51 53 } ··· 65 67 return nil 66 68 } 67 69 68 - func runResolveHandle(cctx *cli.Context) error { 69 - ctx := context.Background() 70 - s := cctx.Args().First() 70 + func runResolveHandle(ctx context.Context, cmd *cli.Command) error { 71 + s := cmd.Args().First() 71 72 if s == "" { 72 73 return fmt.Errorf("need to provide handle as an argument") 73 74 } ··· 87 88 return nil 88 89 } 89 90 90 - func runResolveDID(cctx *cli.Context) error { 91 - ctx := context.Background() 92 - s := cctx.Args().First() 91 + func runResolveDID(ctx context.Context, cmd *cli.Command) error { 92 + s := cmd.Args().First() 93 93 if s == "" { 94 94 fmt.Println("need to provide DID as an argument") 95 95 os.Exit(-1)
+13 -9
atproto/lexicon/cmd/lextool/main.go
··· 1 1 package main 2 2 3 3 import ( 4 + "context" 4 5 "encoding/json" 5 6 "fmt" 6 7 "io" ··· 9 10 10 11 "github.com/bluesky-social/indigo/atproto/lexicon" 11 12 12 - "github.com/urfave/cli/v2" 13 + "github.com/urfave/cli/v3" 13 14 ) 14 15 15 16 func main() { 16 - app := cli.App{ 17 + app := cli.Command{ 17 18 Name: "lex-tool", 18 19 Usage: "informal debugging CLI tool for atproto lexicons", 19 20 } ··· 41 42 } 42 43 h := slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelDebug}) 43 44 slog.SetDefault(slog.New(h)) 44 - app.RunAndExitOnError() 45 + if err := app.Run(context.Background(), os.Args); err != nil { 46 + slog.Error("command failed", "error", err) 47 + os.Exit(-1) 48 + } 45 49 } 46 50 47 - func runParseSchema(cctx *cli.Context) error { 48 - p := cctx.Args().First() 51 + func runParseSchema(ctx context.Context, cmd *cli.Command) error { 52 + p := cmd.Args().First() 49 53 if p == "" { 50 54 return fmt.Errorf("need to provide path to a schema file as an argument") 51 55 } ··· 73 77 return nil 74 78 } 75 79 76 - func runLoadDirectory(cctx *cli.Context) error { 77 - p := cctx.Args().First() 80 + func runLoadDirectory(ctx context.Context, cmd *cli.Command) error { 81 + p := cmd.Args().First() 78 82 if p == "" { 79 83 return fmt.Errorf("need to provide directory path as an argument") 80 84 } ··· 89 93 return nil 90 94 } 91 95 92 - func runResolve(cctx *cli.Context) error { 93 - ref := cctx.Args().First() 96 + func runResolve(ctx context.Context, cmd *cli.Command) error { 97 + ref := cmd.Args().First() 94 98 if ref == "" { 95 99 return fmt.Errorf("need to provide NSID as an argument") 96 100 }
+3 -4
atproto/lexicon/cmd/lextool/net.go
··· 12 12 "github.com/bluesky-social/indigo/atproto/lexicon" 13 13 "github.com/bluesky-social/indigo/atproto/syntax" 14 14 15 - "github.com/urfave/cli/v2" 15 + "github.com/urfave/cli/v3" 16 16 ) 17 17 18 - func runValidateRecord(cctx *cli.Context) error { 19 - ctx := context.Background() 20 - args := cctx.Args().Slice() 18 + func runValidateRecord(ctx context.Context, cmd *cli.Command) error { 19 + args := cmd.Args().Slice() 21 20 if len(args) != 2 { 22 21 return fmt.Errorf("expected two args (catalog path and AT-URI)") 23 22 }
+4 -5
atproto/repo/cmd/repo-tool/firehose.go
··· 16 16 17 17 "github.com/earthboundkid/versioninfo/v2" 18 18 "github.com/gorilla/websocket" 19 - "github.com/urfave/cli/v2" 19 + "github.com/urfave/cli/v3" 20 20 ) 21 21 22 22 // write out error cases as JSON files to disk, for use in regression tests 23 23 var CAPTURE_TEST_CASES = false 24 24 25 - func runVerifyFirehose(cctx *cli.Context) error { 26 - ctx := context.Background() 25 + func runVerifyFirehose(ctx context.Context, cmd *cli.Command) error { 27 26 28 - slog.SetDefault(configLogger(cctx, os.Stdout)) 27 + slog.SetDefault(configLogger(ctx, cmd, os.Stdout)) 29 28 30 - relayHost := cctx.String("relay-host") 29 + relayHost := cmd.String("relay-host") 31 30 32 31 dialer := websocket.DefaultDialer 33 32 u, err := url.Parse(relayHost)
+14 -13
atproto/repo/cmd/repo-tool/main.go
··· 12 12 "github.com/bluesky-social/indigo/atproto/repo" 13 13 "github.com/bluesky-social/indigo/atproto/syntax" 14 14 15 - "github.com/urfave/cli/v2" 15 + "github.com/urfave/cli/v3" 16 16 ) 17 17 18 18 func main() { 19 - app := cli.App{ 19 + app := cli.Command{ 20 20 Name: "repo-tool", 21 21 Usage: "development tool for atproto MST trees, CAR files, etc", 22 22 Flags: []cli.Flag{ 23 23 &cli.StringFlag{ 24 24 Name: "log-level", 25 25 Usage: "log verbosity level (eg: warn, info, debug)", 26 - EnvVars: []string{"BEEMO_LOG_LEVEL", "GO_LOG_LEVEL", "LOG_LEVEL"}, 26 + Sources: cli.EnvVars("BEEMO_LOG_LEVEL", "GO_LOG_LEVEL", "LOG_LEVEL"), 27 27 }, 28 28 }, 29 29 } ··· 49 49 Name: "relay-host", 50 50 Usage: "method, hostname, and port of Relay instance (websocket)", 51 51 Value: "wss://bsky.network", 52 - EnvVars: []string{"ATP_RELAY_HOST"}, 52 + Sources: cli.EnvVars("ATP_RELAY_HOST"), 53 53 }, 54 54 }, 55 55 }, 56 56 } 57 57 h := slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelDebug}) 58 58 slog.SetDefault(slog.New(h)) 59 - app.RunAndExitOnError() 59 + if err := app.Run(context.Background(), os.Args); err != nil { 60 + slog.Error("command failed", "error", err) 61 + os.Exit(-1) 62 + } 60 63 } 61 64 62 - func configLogger(cctx *cli.Context, writer io.Writer) *slog.Logger { 65 + func configLogger(ctx context.Context, cmd *cli.Command, writer io.Writer) *slog.Logger { 63 66 var level slog.Level 64 - switch strings.ToLower(cctx.String("log-level")) { 67 + switch strings.ToLower(cmd.String("log-level")) { 65 68 case "error": 66 69 level = slog.LevelError 67 70 case "warn": ··· 80 83 return logger 81 84 } 82 85 83 - func runVerifyCarMst(cctx *cli.Context) error { 84 - ctx := context.Background() 85 - p := cctx.Args().First() 86 + func runVerifyCarMst(ctx context.Context, cmd *cli.Command) error { 87 + p := cmd.Args().First() 86 88 if p == "" { 87 89 return fmt.Errorf("need to provide path to CAR file") 88 90 } ··· 110 112 return nil 111 113 } 112 114 113 - func runVerifyCarSignature(cctx *cli.Context) error { 114 - ctx := context.Background() 115 + func runVerifyCarSignature(ctx context.Context, cmd *cli.Command) error { 115 116 dir := identity.DefaultDirectory() 116 117 117 - p := cctx.Args().First() 118 + p := cmd.Args().First() 118 119 if p == "" { 119 120 return fmt.Errorf("need to provide path to CAR file") 120 121 }
+11 -7
atproto/syntax/cmd/atp-syntax/main.go
··· 1 1 package main 2 2 3 3 import ( 4 + "context" 4 5 "fmt" 5 6 "log/slog" 6 7 "os" 7 8 8 9 "github.com/bluesky-social/indigo/atproto/syntax" 9 10 10 - "github.com/urfave/cli/v2" 11 + "github.com/urfave/cli/v3" 11 12 ) 12 13 13 14 func main() { 14 - app := cli.App{ 15 + app := cli.Command{ 15 16 Name: "atp-syntax", 16 17 Usage: "informal debugging CLI tool for atproto syntax (identifiers)", 17 18 } ··· 31 32 } 32 33 h := slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelDebug}) 33 34 slog.SetDefault(slog.New(h)) 34 - app.RunAndExitOnError() 35 + if err := app.Run(context.Background(), os.Args); err != nil { 36 + slog.Error("command failed", "error", err) 37 + os.Exit(-1) 38 + } 35 39 } 36 40 37 - func runParseTID(cctx *cli.Context) error { 38 - s := cctx.Args().First() 41 + func runParseTID(ctx context.Context, cmd *cli.Command) error { 42 + s := cmd.Args().First() 39 43 if s == "" { 40 44 return fmt.Errorf("need to provide identifier as an argument") 41 45 } ··· 50 54 return nil 51 55 } 52 56 53 - func runParseDID(cctx *cli.Context) error { 54 - s := cctx.Args().First() 57 + func runParseDID(ctx context.Context, cmd *cli.Command) error { 58 + s := cmd.Args().First() 55 59 if s == "" { 56 60 return fmt.Errorf("need to provide identifier as an argument") 57 61 }