Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: refactor gnoblog-cli #63

Merged
merged 51 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
95ad6c3
start refac
leohhhn Jan 18, 2024
b1bc15f
add cmds
leohhhn Jan 18, 2024
0e46514
wip setup post command
leohhhn Jan 19, 2024
6b9f1a2
wip save, move things around
leohhhn Jan 20, 2024
bc0154f
finished singlepost
leohhhn Jan 20, 2024
970e308
added comments
leohhhn Jan 20, 2024
009478c
extract errors
leohhhn Jan 22, 2024
bcc1656
Merge branch 'main' into refac/cli
leohhhn Jan 29, 2024
8bd0b16
support multicall
leohhhn Feb 1, 2024
d6f9dd0
update gno version
leohhhn Feb 2, 2024
13b024c
update titles & remove title frontmatter
leohhhn Feb 2, 2024
d68efc4
Merge branch 'main' into refac/cli
leohhhn Feb 2, 2024
22622cc
add title & disclaimer to poc2 for consistency
leohhhn Feb 2, 2024
4deb428
update cfg caller
leohhhn Feb 2, 2024
e3efbc3
remove validate-chain func
leohhhn Feb 2, 2024
53a7e75
fix post title parsing
leohhhn Feb 12, 2024
eda9b5d
fix
leohhhn Feb 12, 2024
df3b7ca
chore: better error output
moul Feb 13, 2024
83f0e18
chore: fmt + tidy
moul Feb 13, 2024
5c21029
chore: fix frontmatter parsing
moul Feb 13, 2024
f1437ec
chore: add missing errcheck
moul Feb 13, 2024
2f41a71
chore: fixup
moul Feb 13, 2024
736b4b0
move folders
leohhhn Feb 13, 2024
54e4d9b
add gitignore, fix package names
leohhhn Feb 13, 2024
68778e0
unify post function, minor modifications
leohhhn Feb 27, 2024
467d631
fix md text in posts
leohhhn Feb 27, 2024
5e7efe3
Merge branch 'main' into refac/cli
leohhhn Feb 27, 2024
9294311
move err check
leohhhn Feb 27, 2024
3399548
move IO init to main
leohhhn Feb 27, 2024
eb04b51
add comments, fix removeWhitespace
leohhhn Feb 27, 2024
6f5d2b6
clarify error
leohhhn Feb 27, 2024
ad2f567
add key check
leohhhn Feb 27, 2024
3d32a97
move parsePost, change err check
leohhhn Feb 29, 2024
6b2baa9
change post func signature
leohhhn Feb 29, 2024
c1b8632
add initial test & mocks
leohhhn Feb 29, 2024
1318afb
integration test setup
leohhhn Feb 29, 2024
415a256
remove ./build
leohhhn Feb 29, 2024
b5113be
fix leftover titles
leohhhn Feb 29, 2024
3f04986
add output confirmation
leohhhn Mar 1, 2024
3a17270
wip integ tests
leohhhn Mar 1, 2024
4579742
remove integration test setup
leohhhn Mar 4, 2024
7f1aa96
use tm2/pkg/commands instead of ffcli
leohhhn Mar 4, 2024
cbeb3cc
update err message
leohhhn Mar 4, 2024
2928fb2
updat err msg again
leohhhn Mar 4, 2024
5643778
add condition
leohhhn Mar 4, 2024
5838a07
make if more readable, add exit condition
leohhhn Mar 4, 2024
fe12e9a
go mod tidy
leohhhn Mar 4, 2024
d8c0de0
add readme
leohhhn Mar 4, 2024
1b5e837
update readme
leohhhn Mar 4, 2024
daf6485
update makefile, chagne error
leohhhn Mar 4, 2024
849f47c
update main readme
leohhhn Mar 4, 2024
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ reporting/reporting
reporting/output
.idea
.DS_Store

./build
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
install:
go install ./gnoblog-cli
go install ./cmd/gnoblog-cli

test:
go test -v ./...
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The blog posts are written in markdown format, and include a frontmatter prefix

See [CONTRIBUTING.md](./CONTRIBUTING.md).

## CLI ([`./gnoblog-cli`](./gnoblog-cli))
## CLI ([`./gnoblog-cli`](./cmd/gnoblog-cli))

_See [#1](https://github.com/gnolang/blog/issues/1)_

Expand Down
27 changes: 27 additions & 0 deletions cmd/gnoblog-cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# `gnoblog-cli`

`gnoblog-cli` is a configurable tool that allows for easy deployment of blog posts to the
`r/gnoland/blog` realm.

All blog posts posted with `gnoblog-cli` need to be in the correct format:
- Filename: `README.md`,
- Frontmatter must be of a specific format,
- There must be an H1 in below the frontmatter, which will be treated as the post title.

For reference, see existing posts, like [Peace!](../../posts/2022-05-02_peace)

`gnoblog-cli` utilizes keys from the local Gno keybase to deploy to
the blog realm, whose path is configurable via the `--pkgpath` flag.

`gnoblog-cli` can has the ability to:
- Post a single blog post `README.md` file to the chain, in which case
it takes the direct path to the file as an argument,
- Batch post multiple `README.md` files by recursive looking through directories,
finding `README.md`s, and pack all of them to a single transaction to be
broadcast to the chain.






26 changes: 26 additions & 0 deletions cmd/gnoblog-cli/clients.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package main

import (
"github.com/gnolang/gno/gno.land/pkg/gnoclient"
rpcclient "github.com/gnolang/gno/tm2/pkg/bft/rpc/client"
"github.com/gnolang/gno/tm2/pkg/crypto/keys"
)

func initSigner(cfg *cliCfg, password string) (gnoclient.SignerFromKeybase, error) {
kb, err := keys.NewKeyBaseFromDir(cfg.GnoHome)
if err != nil {
return gnoclient.SignerFromKeybase{}, err
}

return gnoclient.SignerFromKeybase{
Keybase: kb,
Account: cfg.KeyName,
Password: password,
ChainID: cfg.ChainId,
}, nil
}

func initRPCClient(cfg *cliCfg) rpcclient.Client {
remote := cfg.Remote // todo: validate if chainID & remote match?
return rpcclient.NewHTTP(remote, "/websocket")
}
9 changes: 9 additions & 0 deletions cmd/gnoblog-cli/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package main

import "errors"

var (
ErrInvalidNumberOfArgs = errors.New("invalid number of args; please input exactly 1 argument")
ErrEmptyKeyName = errors.New("key name cannot be empty")
ErrNoNewOrChangedPosts = errors.New("no new posts have been added, nor have any existing posts been changed")
)
31 changes: 31 additions & 0 deletions cmd/gnoblog-cli/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package main

import (
"context"
"github.com/gnolang/gno/tm2/pkg/commands"
"os"
)

func main() {
io := commands.NewDefaultIO()
cmd := newRootCmd(io)

cmd.Execute(context.Background(), os.Args[1:])
}

func newRootCmd(io commands.IO) *commands.Command {
cmd := commands.NewCommand(
commands.Metadata{
ShortUsage: "<subcommand> [flags] [<arg>...]",
LongHelp: "The CLI for easy use of the r/blog realm",
},
commands.NewEmptyConfig(),
commands.HelpExec,
)

cmd.AddSubCommands(
newPostCommand(io),
)

return cmd
}
90 changes: 90 additions & 0 deletions cmd/gnoblog-cli/mock_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package main

import (
"io"
)

type (
mockGetPassword func() (string, error)
)

type mockIO struct {
getPassword mockGetPassword
}

func (m mockIO) In() io.Reader {
//TODO implement me
panic("implement me")
}

func (m mockIO) Out() io.WriteCloser {
//TODO implement me
panic("implement me")
}

func (m mockIO) Err() io.WriteCloser {
//TODO implement me
panic("implement me")
}

func (m mockIO) SetIn(in io.Reader) {
//TODO implement me
panic("implement me")
}

func (m mockIO) SetOut(out io.WriteCloser) {
//TODO implement me
panic("implement me")
}

func (m mockIO) SetErr(err io.WriteCloser) {
//TODO implement me
panic("implement me")
}

func (m mockIO) Println(args ...interface{}) {
//TODO implement me
panic("implement me")
}

func (m mockIO) Printf(format string, args ...interface{}) {
//TODO implement me
panic("implement me")
}

func (m mockIO) Printfln(format string, args ...interface{}) {
//TODO implement me
panic("implement me")
}

func (m mockIO) ErrPrintln(args ...interface{}) {
//TODO implement me
panic("implement me")
}

func (m mockIO) ErrPrintfln(format string, args ...interface{}) {
//TODO implement me
panic("implement me")
}

func (m mockIO) GetCheckPassword(prompts [2]string, insecure bool) (string, error) {
//TODO implement me
panic("implement me")
}

func (m mockIO) GetConfirmation(prompt string) (bool, error) {
//TODO implement me
panic("implement me")
}

func (m mockIO) GetPassword(prompt string, insecure bool) (string, error) {
if m.getPassword != nil {
return m.getPassword()
}
return "", nil
}

func (m mockIO) GetString(prompt string) (string, error) {
//TODO implement me
panic("implement me")
}
Loading
Loading