Skip to content

Commit

Permalink
move style to cli
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBger committed Nov 19, 2024
1 parent a7bf1b7 commit bdfe760
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 97 deletions.
7 changes: 4 additions & 3 deletions cmd/substreams/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"errors"
"fmt"
"github.com/streamingfast/cli"
"os"
"strings"

Expand All @@ -27,9 +28,9 @@ func runAuthE(cmd *cobra.Command, args []string) error {
fmt.Println("Open this link to authenticate on The Graph Market:")
fmt.Println()
if localDevelopment == "true" {
fmt.Println(" " + purpleStyle.Render("http://localhost:3000/auth/substreams-devenv"))
fmt.Println(" " + cli.PurpleStyle.Render("http://localhost:3000/auth/substreams-devenv"))
} else {
fmt.Println(" " + purpleStyle.Render("https://thegraph.market/auth/substreams-devenv"))
fmt.Println(" " + cli.PurpleStyle.Render("https://thegraph.market/auth/substreams-devenv"))
}
fmt.Println("")

Expand Down Expand Up @@ -67,7 +68,7 @@ func runAuthE(cmd *cobra.Command, args []string) error {

fmt.Println("Load credentials in current terminal with the following command:")
fmt.Println("")
fmt.Println(purpleStyle.Render(" . ./.substreams.env"))
fmt.Println(cli.PurpleStyle.Render(" . ./.substreams.env"))
fmt.Println()

return nil
Expand Down
26 changes: 3 additions & 23 deletions cmd/substreams/registry-login.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ package main
import (
"errors"
"fmt"
"github.com/charmbracelet/lipgloss"
"github.com/streamingfast/cli/utils"
"os"
"path/filepath"

"github.com/charmbracelet/huh"
"github.com/charmbracelet/lipgloss"

"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -36,7 +35,7 @@ func runRegistryLoginE(cmd *cobra.Command, args []string) error {

isFileExists := checkFileExists(registryTokenFilename)
if isFileExists {
confirmOverwrite, err := runConfirmForm("Token already saved to ~/.config/substreams/registry-token, do you want to overwrite it?")
confirmOverwrite, err := utils.RunConfirmForm("Token already saved to ~/.config/substreams/registry-token, do you want to overwrite it?")
if err != nil {
return fmt.Errorf("running confirm form: %w", err)
}
Expand Down Expand Up @@ -73,22 +72,3 @@ func checkFileExists(filePath string) bool {
return !errors.Is(err, os.ErrNotExist)
}

func runConfirmForm(title string) (bool, error) {
confirmOverwrite := true

form := huh.NewForm(
huh.NewGroup(
huh.NewConfirm().
Title(title).
Value(&confirmOverwrite).
Affirmative("Yes").
Negative("No"),
),
)

if err := form.Run(); err != nil {
return false, fmt.Errorf("error running form: %w", err)
}

return confirmOverwrite, nil
}
14 changes: 8 additions & 6 deletions cmd/substreams/registry-publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"bytes"
"errors"
"fmt"
"github.com/streamingfast/cli"
"github.com/streamingfast/cli/utils"
"io"
"mime/multipart"
"net/http"
Expand Down Expand Up @@ -72,7 +74,7 @@ func runRegistryPublish(cmd *cobra.Command, args []string) (err error) {
warnIncompletePackage(spkg)
printPackageDetails(spkg)

confirm, err := runConfirmForm("Would you like to publish this package?")
confirm, err := utils.RunConfirmForm("Would you like to publish this package?")
if err != nil {
return fmt.Errorf("running confirm form %w", err)
}
Expand Down Expand Up @@ -131,17 +133,17 @@ func runRegistryPublish(cmd *cobra.Command, args []string) (err error) {
if resp.StatusCode != http.StatusOK {
if resp.StatusCode == http.StatusUnauthorized {
fmt.Println("")
fmt.Println(errorStyle.Render("Failed to publish package"))
fmt.Println(errorStyle.Render("Reason: " + string(b)))
fmt.Println(cli.ErrorStyle.Render("Failed to publish package"))
fmt.Println(cli.ErrorStyle.Render("Reason: " + string(b)))
fmt.Println("Make sure you are properly authenticated with:")
fmt.Println("")
fmt.Println(purpleStyle.Render("substreams registry login"))
fmt.Println(cli.PurpleStyle.Render("substreams registry login"))
return nil
}

fmt.Println("")
fmt.Println(errorStyle.Render("Failed to publish package"))
fmt.Println(errorStyle.Render("Reason: " + string(b)))
fmt.Println(cli.ErrorStyle.Render("Failed to publish package"))
fmt.Println(cli.ErrorStyle.Render("Reason: " + string(b)))
return nil
}

Expand Down
8 changes: 0 additions & 8 deletions cmd/substreams/styles.go

This file was deleted.

19 changes: 10 additions & 9 deletions cmd/substreams/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"github.com/spf13/cobra"
"github.com/streamingfast/cli"
pbsubstreams "github.com/streamingfast/substreams/pb/sf/substreams/v1"
"strconv"
"strings"
Expand Down Expand Up @@ -59,34 +60,34 @@ func readStopBlockFlag(cmd *cobra.Command, startBlock int64, flagName string, wi
func warnIncompletePackage(spkg *pbsubstreams.Package) {
if len(spkg.PackageMeta) > 0 {
if spkg.PackageMeta[0].Doc == "" {
fmt.Println(warningStyle.Render("Warning: README not found for this package."))
fmt.Println(cli.WarningStyle.Render("Warning: README not found for this package."))
}

if spkg.PackageMeta[0].Url == "" {
fmt.Println(warningStyle.Render("Warning: URL is not set for this package."))
fmt.Println(cli.WarningStyle.Render("Warning: URL is not set for this package."))
}

if spkg.PackageMeta[0].Description == "" {
fmt.Println(warningStyle.Render("Warning: Description is not set for this package."))
fmt.Println(cli.WarningStyle.Render("Warning: Description is not set for this package."))
}
}

if spkg.Network == "" {
fmt.Println(warningStyle.Render("Warning: Network is not set for this package."))
fmt.Println(cli.WarningStyle.Render("Warning: Network is not set for this package."))
}

if spkg.Image == nil {
fmt.Println(warningStyle.Render("Warning: Image is not set for this package."))
fmt.Println(cli.WarningStyle.Render("Warning: Image is not set for this package."))
}

fmt.Println()
}

func printPackageDetails(spkg *pbsubstreams.Package) {
fmt.Println()
fmt.Println(headerStyle.Render("Package Details"))
fmt.Printf("%s: %s\n", purpleStyle.Render("Name"), spkg.PackageMeta[0].Name)
fmt.Printf("%s: %s\n", purpleStyle.Render("Version"), spkg.PackageMeta[0].Version)
fmt.Printf("%s: %s\n", purpleStyle.Render("URL"), spkg.PackageMeta[0].Url)
fmt.Println(cli.HeaderStyle.Render("Package Details"))
fmt.Printf("%s: %s\n", cli.PurpleStyle.Render("Name"), spkg.PackageMeta[0].Name)
fmt.Printf("%s: %s\n", cli.PurpleStyle.Render("Version"), spkg.PackageMeta[0].Version)
fmt.Printf("%s: %s\n", cli.PurpleStyle.Render("URL"), spkg.PackageMeta[0].Url)
fmt.Println()
}
32 changes: 16 additions & 16 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/streamingfast/substreams

go 1.21
go 1.22

toolchain go1.23.2

require (
github.com/abourget/llerrgroup v0.2.0
Expand All @@ -9,7 +11,7 @@ require (
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5 // indirect
github.com/streamingfast/bstream v0.0.2-0.20240916154503-c9c5c8bbeca0
github.com/streamingfast/cli v0.0.4-0.20230825151644-8cc84512cd80
github.com/streamingfast/cli v0.0.4-0.20241119021815-815afa473375
github.com/streamingfast/dauth v0.0.0-20240219205130-bfe428489338
github.com/streamingfast/dbin v0.9.1-0.20231117225723-59790c798e2c
github.com/streamingfast/derr v0.0.0-20230515163924-8570aaa43fe1
Expand All @@ -34,13 +36,13 @@ require (
github.com/alecthomas/participle v0.7.1
github.com/bmatcuk/doublestar/v4 v4.6.1
github.com/bytecodealliance/wasmtime-go/v4 v4.0.0
github.com/charmbracelet/bubbles v0.18.0
github.com/charmbracelet/bubbletea v0.27.0
github.com/charmbracelet/bubbles v0.20.0
github.com/charmbracelet/bubbletea v1.1.0
github.com/charmbracelet/glamour v0.7.0
github.com/charmbracelet/huh v0.5.2
github.com/charmbracelet/huh v0.6.0
github.com/charmbracelet/huh/spinner v0.0.0-20240806005253-b7436a76999a
github.com/charmbracelet/lipgloss v0.12.1
github.com/charmbracelet/x/ansi v0.1.4
github.com/charmbracelet/lipgloss v1.0.0
github.com/charmbracelet/x/ansi v0.4.2
github.com/docker/cli v24.0.6+incompatible
github.com/dustin/go-humanize v1.0.1
github.com/golang-cz/textcase v1.2.1
Expand All @@ -51,7 +53,7 @@ require (
github.com/mattn/go-isatty v0.0.20
github.com/mitchellh/go-testing-interface v1.14.1
github.com/muesli/reflow v0.3.0
github.com/muesli/termenv v0.15.2
github.com/muesli/termenv v0.15.3-0.20240618155329-98d742f6907a
github.com/prometheus/client_golang v1.16.0
github.com/protocolbuffers/protoscope v0.0.0-20221109213918-8e7a6aafa2c9
github.com/rs/cors v1.10.0
Expand Down Expand Up @@ -83,23 +85,21 @@ require (
github.com/alecthomas/chroma/v2 v2.8.0 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/bits-and-blooms/bitset v1.12.0 // indirect
github.com/bobg/go-generics/v2 v2.2.2 // indirect
github.com/bobg/go-generics/v3 v3.4.0 // indirect
github.com/catppuccin/go v0.2.0 // indirect
github.com/charmbracelet/x/exp/strings v0.0.0-20240722160745-212f7b056ed0 // indirect
github.com/charmbracelet/x/input v0.1.3 // indirect
github.com/charmbracelet/x/term v0.1.1 // indirect
github.com/charmbracelet/x/windows v0.1.2 // indirect
github.com/charmbracelet/x/term v0.2.0 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/manifoldco/promptui v0.9.0 // indirect
github.com/mattn/go-sqlite3 v1.14.17 // indirect
github.com/mitchellh/hashstructure/v2 v2.0.2 // indirect
github.com/mschoch/smat v0.2.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/sahilm/fuzzy v0.1.1-0.20230530133925-c48e322e2a8f // indirect
github.com/sahilm/fuzzy v0.1.1 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.uber.org/goleak v1.3.0 // indirect
golang.org/x/time v0.5.0 // indirect
Expand Down Expand Up @@ -194,9 +194,9 @@ require (
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/term v0.20.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/text v0.18.0 // indirect
google.golang.org/api v0.172.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect
Expand Down
Loading

0 comments on commit bdfe760

Please sign in to comment.