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
92 changes: 92 additions & 0 deletions cmd/spawn/docs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package main

import (
"io"
"io/fs"
"os"
"path"

"github.com/charmbracelet/glow/ui"
"github.com/rollchains/spawn/docs"
"github.com/spf13/cobra"
"golang.org/x/term"
)

var DocsCmd = &cobra.Command{
Use: "docs",
Short: "View Spawn Documentation",
RunE: func(cmd *cobra.Command, args []string) error {
dirPath := path.Join(os.TempDir(), "spawn", "docs")

err := fs.WalkDir(docs.Docs, ".", func(relPath string, d fs.DirEntry, e error) error {
newPath := path.Join(dirPath, relPath)

if d.IsDir() {
return os.MkdirAll(newPath, 0755)
}

fi, err := docs.Docs.Open(relPath)
if err != nil {
return err
}
defer fi.Close()

fo, err := os.Create(newPath)
if err != nil {
return err
}
defer fo.Close()

_, err = io.Copy(fo, fi)
if err != nil {
return err
}

return nil
})
if err != nil {
return err
}
defer os.RemoveAll(dirPath)

return View(dirPath)
},
}

// orginal source: https://github.com/ignite/cli/blob/main/ignite/pkg/markdownviewer/markdownviewer.go
func View(path string) error {
conf, err := config(path)
if err != nil {
return err
}

_, err = ui.NewProgram(conf).Run()
return err
}

func config(path string) (ui.Config, error) {
var width uint

w, _, err := term.GetSize(int(os.Stdout.Fd()))
if err != nil {
return ui.Config{}, err
}
width = uint(w)
if width > 120 {
width = 120
}

docTypes := ui.NewDocTypeSet()
docTypes.Add(ui.LocalDoc)

conf := ui.Config{
WorkingDirectory: path,
DocumentTypes: docTypes,
GlamourStyle: "auto",
HighPerformancePager: true,
GlamourEnabled: true,
GlamourMaxWidth: width,
}

return conf, nil
}
1 change: 1 addition & 0 deletions cmd/spawn/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func main() {
rootCmd.AddCommand(versionCmd)
rootCmd.AddCommand(ModuleCmd())
rootCmd.AddCommand(ProtoServiceGenerate())
rootCmd.AddCommand(DocsCmd)

applyPluginCmds()

Expand Down
6 changes: 6 additions & 0 deletions docs/embeded.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package docs

import "embed"

//go:embed demo DEPLOYMENTS.md SYSTEM_SETUP.md
var Docs embed.FS
37 changes: 36 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ replace (
)

require (
github.com/charmbracelet/glow v1.5.1
github.com/cosmos/btcutil v1.0.5
github.com/lmittmann/tint v1.0.4
github.com/manifoldco/promptui v0.9.0
Expand All @@ -24,6 +25,7 @@ require (
github.com/strangelove-ventures/interchaintest/v8 v8.5.0
github.com/stretchr/testify v1.9.0
golang.org/x/mod v0.17.0
golang.org/x/term v0.19.0
golang.org/x/text v0.14.0
golang.org/x/tools v0.20.0
)
Expand Down Expand Up @@ -53,15 +55,25 @@ require (
github.com/DataDog/datadog-go v3.2.0+incompatible // indirect
github.com/DataDog/zstd v1.5.5 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/alecthomas/chroma v0.10.0 // indirect
github.com/atotto/clipboard v0.1.4 // indirect
github.com/avast/retry-go/v4 v4.5.1 // indirect
github.com/aws/aws-sdk-go v1.44.224 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect
github.com/bits-and-blooms/bitset v1.10.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/calmh/randomart v1.1.0 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/charmbracelet/bubbles v0.15.0 // indirect
github.com/charmbracelet/bubbletea v0.23.2 // indirect
github.com/charmbracelet/charm v0.8.7 // indirect
github.com/charmbracelet/glamour v0.6.0 // indirect
github.com/charmbracelet/lipgloss v0.6.0 // indirect
github.com/chzyer/readline v1.5.1 // indirect
github.com/cockroachdb/errors v1.11.1 // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
Expand All @@ -70,6 +82,7 @@ require (
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/cometbft/cometbft v0.38.8 // indirect
github.com/cometbft/cometbft-db v0.12.0 // indirect
github.com/containerd/console v1.0.3 // indirect
github.com/cosmos/cosmos-db v1.0.2 // indirect
github.com/cosmos/cosmos-proto v1.0.0-beta.5 // indirect
github.com/cosmos/cosmos-sdk v0.50.7 // indirect
Expand All @@ -88,6 +101,8 @@ require (
github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect
github.com/dgraph-io/badger/v4 v4.2.0 // indirect
github.com/dgraph-io/ristretto v0.1.1 // indirect
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
github.com/dlclark/regexp2 v1.4.0 // indirect
github.com/docker/distribution v2.8.2+incompatible // indirect
github.com/docker/docker v24.0.9+incompatible // indirect
github.com/docker/go-connections v0.5.0 // indirect
Expand Down Expand Up @@ -123,6 +138,7 @@ require (
github.com/google/uuid v1.6.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/gorilla/css v1.0.0 // indirect
github.com/gorilla/handlers v1.5.2 // indirect
github.com/gorilla/mux v1.8.1 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
Expand Down Expand Up @@ -156,16 +172,30 @@ require (
github.com/lib/pq v1.10.7 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/linxGnu/grocksdb v1.8.14 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/meowgorithm/babyenv v1.3.1 // indirect
github.com/microcosm-cc/bluemonday v1.0.23 // indirect
github.com/mikesmitty/edkey v0.0.0-20170222072505-3356ea4e686a // indirect
github.com/minio/highwayhash v1.0.2 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mtibben/percent v0.2.1 // indirect
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/gitcha v0.2.0 // indirect
github.com/muesli/go-app-paths v0.2.2 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/sasquatch v0.0.0-20200811221207-66979d92330a // indirect
github.com/muesli/termenv v0.15.1 // indirect
github.com/ncruces/go-strftime v0.1.9 // indirect
github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc2 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
Expand All @@ -178,12 +208,16 @@ require (
github.com/prometheus/procfs v0.13.0 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/rivo/uniseg v0.4.3 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/rs/cors v1.8.3 // indirect
github.com/rs/zerolog v1.32.0 // indirect
github.com/sabhiram/go-gitignore v0.0.0-20180611051255-d3107576ba94 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sahilm/fuzzy v0.1.0 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/segmentio/ksuid v1.0.4 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
Expand All @@ -193,6 +227,8 @@ require (
github.com/tendermint/go-amino v0.16.0 // indirect
github.com/tidwall/btree v1.7.0 // indirect
github.com/ulikunitz/xz v0.5.11 // indirect
github.com/yuin/goldmark v1.5.2 // indirect
github.com/yuin/goldmark-emoji v1.0.1 // indirect
github.com/zondax/hid v0.9.2 // indirect
github.com/zondax/ledger-go v0.14.3 // indirect
go.etcd.io/bbolt v1.4.0-alpha.0.0.20240404170359-43604f3112c5 // indirect
Expand All @@ -210,7 +246,6 @@ require (
golang.org/x/oauth2 v0.18.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/term v0.19.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/api v0.162.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
Expand Down
Loading