Skip to content

Commit

Permalink
add warning logs + package details on publish + pack
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBger committed Nov 14, 2024
1 parent 78c1d0b commit 12c2948
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 15 deletions.
8 changes: 3 additions & 5 deletions cmd/substreams/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"strings"

"github.com/charmbracelet/huh"
"github.com/charmbracelet/lipgloss"
"github.com/spf13/cobra"
)

Expand All @@ -27,11 +26,10 @@ func runAuthE(cmd *cobra.Command, args []string) error {

fmt.Println("Open this link to authenticate on The Graph Market:")
fmt.Println()
linkStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("12"))
if localDevelopment == "true" {
fmt.Println(" " + linkStyle.Render("http://localhost:3000/auth/substreams-devenv"))
fmt.Println(" " + purpleStyle.Render("http://localhost:3000/auth/substreams-devenv"))
} else {
fmt.Println(" " + linkStyle.Render("https://thegraph.market/auth/substreams-devenv"))
fmt.Println(" " + purpleStyle.Render("https://thegraph.market/auth/substreams-devenv"))
}
fmt.Println("")

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

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

return nil
Expand Down
1 change: 1 addition & 0 deletions cmd/substreams/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ func findManifest() (string, error) {
func runCommandInDir(ctx context.Context, dir string, cmdArgs []string) error {
cmd := exec.CommandContext(ctx, cmdArgs[0], cmdArgs[1:]...)
cmd.Env = append(os.Environ(), "CARGO_TERM_COLOR=always")
cmd.Env = append(cmd.Env, "CLICOLOR_FORCE=true")
cmd.Dir = dir

stdoutPipe, err := cmd.StdoutPipe()
Expand Down
3 changes: 3 additions & 0 deletions cmd/substreams/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ func runPack(cmd *cobra.Command, args []string) error {
return fmt.Errorf("reading manifest %q: %w", manifestPath, err)
}

warnIncompletePackage(pkgBundle.Package)
printPackageDetails(pkgBundle.Package)

if pkgBundle == nil {
return fmt.Errorf("no package found")
}
Expand Down
10 changes: 2 additions & 8 deletions cmd/substreams/registry-publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,8 @@ func runRegistryPublish(cmd *cobra.Command, args []string) (err error) {

spkg := pkgBundle.Package

style := lipgloss.NewStyle().Foreground(lipgloss.Color("12"))
headerStyle := lipgloss.NewStyle().Bold(true)
fmt.Println()
fmt.Println(headerStyle.Render("Package Details"))
fmt.Printf("%s: %s\n", style.Render("Name"), spkg.PackageMeta[0].Name)
fmt.Printf("%s: %s\n", style.Render("Version"), spkg.PackageMeta[0].Version)
fmt.Printf("%s: %s\n", style.Render("URL"), spkg.PackageMeta[0].Url)
fmt.Println()
warnIncompletePackage(spkg)
printPackageDetails(spkg)

confirm, err := runConfirmForm("Would you like to publish this package?")
if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions cmd/substreams/styles.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "github.com/charmbracelet/lipgloss"

var warningStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("11"))
var purpleStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("12"))
var headerStyle = lipgloss.NewStyle().Bold(true)
36 changes: 36 additions & 0 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"
pbsubstreams "github.com/streamingfast/substreams/pb/sf/substreams/v1"
"strconv"
"strings"
)
Expand Down Expand Up @@ -54,3 +55,38 @@ func readStopBlockFlag(cmd *cobra.Command, startBlock int64, flagName string, wi

return endBlock, nil
}

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."))
}

if spkg.PackageMeta[0].Url == "" {
fmt.Println(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."))
}
}

if spkg.Network == "" {
fmt.Println(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()
}

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()
}
4 changes: 2 additions & 2 deletions manifest/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,9 @@ func (m *Manifest) readFileFromName(filename string) ([]byte, error) {
func (r *manifestConverter) convertToPkg(m *Manifest) (pkg *pbsubstreams.Package, err error) {
doc := m.Package.Doc
if doc != "" {
fmt.Println("Deprecated: the 'package.doc' field is deprecated. The README.md file is picked up instead.")
fmt.Println("Deprecated: the 'package.doc' field is deprecated. The README.md file is picked up instead.\n")

Check failure on line 349 in manifest/package.go

View workflow job for this annotation

GitHub Actions / Test (1.21.x, ubuntu-latest)

fmt.Println arg list ends with redundant newline

Check failure on line 349 in manifest/package.go

View workflow job for this annotation

GitHub Actions / Test (1.21.x, macos-latest)

fmt.Println arg list ends with redundant newline
}

readmeContent, err := m.readFileFromName("README.md")
if err != nil {
if !os.IsNotExist(err) {
Expand All @@ -358,7 +359,6 @@ func (r *manifestConverter) convertToPkg(m *Manifest) (pkg *pbsubstreams.Package
if !os.IsNotExist(err) {
return nil, fmt.Errorf("reading file: %w", err)
}
fmt.Println("Warning: README.md file not found, no documentation will be packaged")
err = nil
}
}
Expand Down

0 comments on commit 12c2948

Please sign in to comment.