Skip to content

Commit

Permalink
feat: add contribs/gnomd (#1256)
Browse files Browse the repository at this point in the history
This PR adds a `contribs/gnomd` binary.
Please review PR #1001 for the `maketx run`. 

Additionally, this PR introduces the `contribs/` folder. It allows the
creation of `contribs/gno*` Go packages, Python/Rust/Shell/… scripts.
This approach keeps the main `gno`, `gnokey`, and `gnoland` simple while
adhering to the Unix philosophy and incorporating several specific gno
commands.

![CleanShot 2023-10-19 at 09 17
40@2x](https://github.com/gnolang/gno/assets/94029/9b92bf18-f923-4f70-aea7-a88f185f2342)

---------

Signed-off-by: moul <[email protected]>
Co-authored-by: Morgan <[email protected]>
  • Loading branch information
moul and thehowl authored Nov 8, 2023
1 parent 31d2ce9 commit 11f4359
Show file tree
Hide file tree
Showing 7 changed files with 218 additions and 2 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/contribs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: contribs

on:
push:
branches: [ "master" ]
pull_request:
paths:
- "contribs/**"
- ".github/workflows/contribs.yml"
- "gnovm/**.go"
- "gno.land/**.go"
- "tm2/**.go"

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
install:
strategy:
fail-fast: false
matrix:
goversion: # two latest versions
- "1.21.x"
program:
- "gnomd"
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: ${{ matrix.goversion }}
- run: make install ${{ matrix.program }}
working-directory: contribs
5 changes: 3 additions & 2 deletions .github/workflows/misc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ jobs:

- name: Check go.mods
run: |
sums="$(sha256sum go.mod misc/devdeps/go.mod)"
for path in . ./misc/devdeps; do
gomods=$(find . -type f -name go.mod)
sums="$(sha256sum ${gomods})"
for path in $(dirname $(gomods)); do
env -C $path go mod tidy -v || exit 1
done
echo "$sums" | sha256sum -c
30 changes: 30 additions & 0 deletions contribs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.PHONY: help
help:
@echo "Available make commands:"
@cat Makefile | grep '^[a-z][^:]*:' | cut -d: -f1 | sort | sed 's/^/ /'

.PHONY: install
install: install.gnomd

install.gnomd:; cd gnomd && go install .

.PHONY: clean
clean:
rm -rf build

########################################
# Dev tools
rundep=go run -modfile ../misc/devdeps/go.mod

.PHONY: fmt
GOFMT_FLAGS ?= -w
fmt:
$(rundep) mvdan.cc/gofumpt $(GOFMT_FLAGS) .

########################################
# Test suite
GOTEST_FLAGS ?= -v -p 1 -timeout=30m

.PHONY: test
test:
@echo "nothing to do."
17 changes: 17 additions & 0 deletions contribs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Gno Contribs

This directory houses additional commands and tools designed to enhance your Gno experience.
These tools can range from simple wrappers for `gno`, `gnoland`, and `gnokey` to complete applications.
Some may be Go binaries with their own `go.mod` files, allowing the use of specialized libraries,
while others may be shell scripts or programs written in different languages.

## Contributing Guidelines

If you'd like to contribute a tool to Gno Contribs, please follow these guidelines:

1. **Naming**: Choose a clear and concise name for your tool, starting with one of the prefixes: `gno`, `gnoland`, or `gnokey`,
followed by a short descriptive word or abbreviation.
This naming convention helps users identify the purpose of the tool easily.

2. **User-Friendly**: Ensure that your tool is user-friendly and follows a similar style to other Gno tools,
providing a consistent experience for users.
25 changes: 25 additions & 0 deletions contribs/gnomd/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module github.com/gnolang/gno/contribs/gnomd

go 1.20

require github.com/MichaelMure/go-term-markdown v0.1.4

require (
github.com/MichaelMure/go-term-text v0.3.1 // indirect
github.com/alecthomas/chroma v0.7.1 // indirect
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 // indirect
github.com/disintegration/imaging v1.6.2 // indirect
github.com/dlclark/regexp2 v1.1.6 // indirect
github.com/eliukblau/pixterm/pkg/ansimage v0.0.0-20191210081756-9fb6cf8c2f75 // indirect
github.com/fatih/color v1.9.0 // indirect
github.com/gomarkdown/markdown v0.0.0-20191123064959-2c17d62f5098 // indirect
github.com/kyokomi/emoji/v2 v2.2.8 // indirect
github.com/lucasb-eyer/go-colorful v1.0.3 // indirect
github.com/mattn/go-colorable v0.1.4 // indirect
github.com/mattn/go-isatty v0.0.11 // indirect
github.com/mattn/go-runewidth v0.0.12 // indirect
github.com/rivo/uniseg v0.1.0 // indirect
golang.org/x/image v0.0.0-20191206065243-da761ea9ff43 // indirect
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7 // indirect
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 // indirect
)
70 changes: 70 additions & 0 deletions contribs/gnomd/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions contribs/gnomd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package main

import (
"fmt"
"io/ioutil"
"os"

markdown "github.com/MichaelMure/go-term-markdown"
)

func main() {
// If no arguments are provided, read from stdin
if len(os.Args) <= 1 {
fileContent, err := ioutil.ReadAll(os.Stdin)
checkErr(err)
renderMarkdown("stdin.gno", fileContent)
}

// Iterate through command-line arguments (file paths)
for _, filePath := range os.Args[1:] {
fileContent, err := ioutil.ReadFile(filePath)
checkErr(err)
renderMarkdown(filePath, fileContent)
}
}

func renderMarkdown(filePath string, fileContent []byte) {
fmt.Printf("-- %s --\n", filePath)

result := markdown.Render(string(fileContent), 80, 6)
fmt.Println(string(result))
}

func checkErr(err error) {
if err != nil {
panic(err)
}
}

0 comments on commit 11f4359

Please sign in to comment.