Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmd/replicate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/replicate/cli/internal"
"github.com/replicate/cli/internal/cmd"
"github.com/replicate/cli/internal/cmd/account"
"github.com/replicate/cli/internal/cmd/auth"
"github.com/replicate/cli/internal/cmd/hardware"
"github.com/replicate/cli/internal/cmd/model"
Expand Down Expand Up @@ -35,6 +36,7 @@ func init() {
Title: "Core commands:",
})
for _, cmd := range []*cobra.Command{
account.RootCmd,
auth.RootCmd,
model.RootCmd,
prediction.RootCmd,
Expand All @@ -54,6 +56,7 @@ func init() {
cmd.RunCmd,
cmd.TrainCmd,
cmd.StreamCmd,
cmd.AccountCmd,
} {
rootCmd.AddCommand(cmd)
cmd.GroupID = "alias"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/getkin/kin-openapi v0.123.0
github.com/golangci/golangci-lint v1.55.2
github.com/mattn/go-isatty v0.0.20
github.com/replicate/replicate-go v0.14.2
github.com/replicate/replicate-go v0.15.0
github.com/schollz/progressbar/v3 v3.13.1
github.com/spf13/cobra v1.8.0
github.com/stretchr/testify v1.8.4
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -522,8 +522,8 @@ github.com/quasilyte/regex/syntax v0.0.0-20210819130434-b3f0c404a727 h1:TCg2WBOl
github.com/quasilyte/regex/syntax v0.0.0-20210819130434-b3f0c404a727/go.mod h1:rlzQ04UMyJXu/aOvhd8qT+hvDrFpiwqp8MRXDY9szc0=
github.com/quasilyte/stdinfo v0.0.0-20220114132959-f7386bf02567 h1:M8mH9eK4OUR4lu7Gd+PU1fV2/qnDNfzT635KRSObncs=
github.com/quasilyte/stdinfo v0.0.0-20220114132959-f7386bf02567/go.mod h1:DWNGW8A4Y+GyBgPuaQJuWiy0XYftx4Xm/y5Jqk9I6VQ=
github.com/replicate/replicate-go v0.14.2 h1:XgK+REvYrWs7qDeyugxHA93h31qBhEFk/3p1/p2w3W8=
github.com/replicate/replicate-go v0.14.2/go.mod h1:otIrl1vDmyjNhTzmVmp/mQU3Wt1+3387gFNEsAZq0ig=
github.com/replicate/replicate-go v0.15.0 h1:irjAv6PI9H2o4H3sKkaHuQ35mKNC/0OQqNleYWNA4Sg=
github.com/replicate/replicate-go v0.15.0/go.mod h1:otIrl1vDmyjNhTzmVmp/mQU3Wt1+3387gFNEsAZq0ig=
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
Expand Down
10 changes: 3 additions & 7 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
github.com/googleapis/gax-go/v2 v2.4.0/go.mod h1:XOTVJ59hdnfJLIP/dh8n5CGryZR2LxK9wbMD5+iXC6c=
github.com/gookit/color v1.5.4/go.mod h1:pZJOeOS8DM43rXbp4AZo1n9zCU2qjpcRko0b6/QJi9w=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
github.com/hashicorp/consul/api v1.12.0/go.mod h1:6pVBMo0ebnYdt2S3H87XhekM/HHrUoTD2XXb/VrZVy0=
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
github.com/hashicorp/go-hclog v1.2.0/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ=
Expand Down Expand Up @@ -48,6 +49,8 @@ github.com/replicate/replicate-go v0.8.1 h1:Mza5hWR/R1akZRKwXtA/CQJ2pY4/B9fSCYX+
github.com/replicate/replicate-go v0.8.1/go.mod h1:k9C4+PaYa9+hMRjn4D7ZPHOCUFb8P4jhytsCqcGa2vU=
github.com/replicate/replicate-go v0.13.0 h1:DWpSw8ck+dVK79jcVbg0iWJt4/ajcDaYX7FmiqSh2iI=
github.com/replicate/replicate-go v0.13.0/go.mod h1:k9C4+PaYa9+hMRjn4D7ZPHOCUFb8P4jhytsCqcGa2vU=
github.com/replicate/replicate-go v0.15.0 h1:irjAv6PI9H2o4H3sKkaHuQ35mKNC/0OQqNleYWNA4Sg=
github.com/replicate/replicate-go v0.15.0/go.mod h1:otIrl1vDmyjNhTzmVmp/mQU3Wt1+3387gFNEsAZq0ig=
github.com/sagikazarmark/crypt v0.6.0/go.mod h1:U8+INwJo3nBv1m6A/8OBXAq7Jnpspk5AxSgDyEQcea8=
github.com/sahilm/fuzzy v0.1.0/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y=
github.com/shirou/gopsutil/v3 v3.23.10/go.mod h1:JIE26kpucQi+innVlAUnIEOSBhBUkirr5b44yr55+WE=
Expand All @@ -63,14 +66,7 @@ go.etcd.io/etcd/client/pkg/v3 v3.5.4/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3
go.etcd.io/etcd/client/v2 v2.305.4/go.mod h1:Ud+VUwIi9/uQHOMA+4ekToJ12lTxlv0zB/+DHwTGEbU=
go.etcd.io/etcd/client/v3 v3.5.4/go.mod h1:ZaRkVgBZC+L+dLCjTcF1hRXpgZXQPOvnA/Ak/gq3kiY=
go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E=
go.uber.org/nilaway v0.0.0-20231130193605-0ef3071d1630 h1:d78bN/STgxmCT0mDg+ZgR9EB3Z/lKq2i34sCvw39eMQ=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/exp v0.0.0-20231108232855-2478ac86f678 h1:mchzmB1XO2pMaKFRqk/+MV3mgGG96aqaPXaMifQU47w=
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg=
golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ=
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
golang.org/x/tools v0.15.0 h1:zdAyfUGbYmuVokhzVmghFl2ZJh5QhcfebBgmVPFYA+8=
google.golang.org/api v0.81.0/go.mod h1:FA6Mb/bZxj706H2j+j2d6mHEEaHBmbbWnkfvmorOCko=
google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd/go.mod h1:RAyBrSAP7Fh3Nc84ghnVLDPuV51xc9agzmm4Ph6i0Q4=
18 changes: 18 additions & 0 deletions internal/cmd/account.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cmd

import (
"github.com/spf13/cobra"

"github.com/replicate/cli/internal/cmd/account"
)

var AccountCmd = &cobra.Command{
Use: "account",
Short: `Alias for "accounts current"`,
Aliases: []string{"profile", "whoami"},
RunE: account.CurrentCmd.RunE,
}

func init() {
account.AddCurrentAccountFlags(AccountCmd)
}
71 changes: 71 additions & 0 deletions internal/cmd/account/current.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package account

import (
"encoding/json"
"fmt"

"github.com/cli/browser"
"github.com/spf13/cobra"

"github.com/replicate/cli/internal/client"
"github.com/replicate/cli/internal/util"
)

// CurrentCmd represents the get current account command
var CurrentCmd = &cobra.Command{
Use: "current",
Short: "Show the current account",
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()

r8, err := client.NewClient()
if err != nil {
return err
}

account, err := r8.GetCurrentAccount(ctx)
if err != nil {
return fmt.Errorf("failed to get account: %w", err)
}

if cmd.Flags().Changed("web") {
if util.IsTTY() {
fmt.Println("Opening in browser...")
}

url := "https://replicate.com/" + account.Username
err := browser.OpenURL(url)
if err != nil {
return fmt.Errorf("failed to open browser: %w", err)
}

return nil
}

if cmd.Flags().Changed("json") || !util.IsTTY() {
bytes, err := json.MarshalIndent(account, "", " ")
if err != nil {
return fmt.Errorf("failed to marshal account: %w", err)
}
fmt.Println(string(bytes))
return nil
}

fmt.Printf("Type: %s\n", account.Type)
fmt.Printf("Username: %s\n", account.Username)
fmt.Printf("Name: %s\n", account.Name)
fmt.Printf("GitHub URL: %s\n", account.GithubURL)

return nil
},
}

func init() {
AddCurrentAccountFlags(CurrentCmd)
}

func AddCurrentAccountFlags(cmd *cobra.Command) {
cmd.Flags().Bool("json", false, "Emit JSON")
cmd.Flags().Bool("web", false, "View on web")
cmd.MarkFlagsMutuallyExclusive("json", "web")
}
24 changes: 24 additions & 0 deletions internal/cmd/account/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package account

import (
"github.com/spf13/cobra"
)

var RootCmd = &cobra.Command{
Use: "account [subcommand]",
Short: "Interact with accounts",
Aliases: []string{"accounts", "a"},
}

func init() {
RootCmd.AddGroup(&cobra.Group{
ID: "subcommand",
Title: "Subcommands:",
})
for _, cmd := range []*cobra.Command{
CurrentCmd,
} {
RootCmd.AddCommand(cmd)
cmd.GroupID = "subcommand"
}
}