Skip to content

Commit 2fff03d

Browse files
Migrate from bonzai to kong (#29)
* Migrate from bonzai to kong Significant changes where made between the version of Bonzai I wrote this with and latest. Further, the author deleted their packages meaning we cannot rebuild on machines that don't have them cached. Signed-off-by: Daniel Michaels <dan@danielms.site> * Only run go-releaser on push tag Signed-off-by: Daniel Michaels <dan@danielms.site> * Update build instructions Signed-off-by: Daniel Michaels <dan@danielms.site> * Fix interactive term, use idomatic kong for nested commands Signed-off-by: Daniel Michaels <dan@danielms.site> --------- Signed-off-by: Daniel Michaels <dan@danielms.site>
1 parent c848b74 commit 2fff03d

File tree

16 files changed

+917
-783
lines changed

16 files changed

+917
-783
lines changed

.github/workflows/goreleaser.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
name: goreleaser
22

33
on:
4-
pull_request:
4+
workflow_dispatch:
55
push:
66
tags:
7-
- '*'
7+
- 'v*'
88

99
permissions:
1010
contents: write

ARCHITECTURE.md

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -38,48 +38,6 @@ Zet will use github and git as its storage medium. Each new zet will get a dire
3838

3939
Tags are used for quicker searching. Terminal tools and github do well searching for hashtag prepended names.
4040

41-
### Implementation
42-
43-
Many facets will be stolen from rwxrob/Zet-cmd
44-
https://github.com/rwxrob/cmd-zet
45-
46-
This will be a standalone bonzai branch which can be imported into ds
47-
48-
49-
50-
## Commands
51-
52-
Zet commands required to create, read and edit zet's
53-
54-
### Create
55-
56-
Creating a new Zet is the most common command.
57-
58-
create flow
59-
60-
1. Zet create $1
61-
2. Create $dir
62-
3. Vim $dir/README.md
63-
4. Write contents (see $contents)
64-
5. Git commit -s -a -m $1
65-
6. Git pull -q (prevent conflicts)
66-
7. Git push -s
67-
8. Echo zet pushed as $isosec ($dir name)
68-
69-
### Edit
70-
71-
Editing any previous Zet is achieved by appending the isosec after Zet edit.
72-
73-
### Last
74-
75-
This should open the last Zet in vim.
76-
77-
Finding the last Zet could probably be achieved by identifying the latest dir from the list of dirs
78-
79-
### View
80-
81-
This could be a search option for reading or finding a Zet to edit
82-
8341
## Notes
8442
Todo:
8543

BUILD.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
When updating this repository to a new release the following steps need to be undertaken.
44

5-
1. Update `Cmd.Version` in `zet-cmd/cmd/zet/main.go`
6-
2. Merge to `main` all changes required for the new release
7-
3. Create a new tag to match the `Cmd.Version` with `git tag -a v0.0.0 -m "v0.0.0" -s`
8-
4. Push the tag with `git push --tags` which will trigger `goreleaser` to build new binaries
5+
1. Merge to `main` all changes required for the new release
6+
2. Create a new with `git tag -a v0.0.0 -m "v0.0.0" -s`
7+
3. Push the tag with `git push --tags` which will trigger `goreleaser` to build new binaries

README.md

Lines changed: 12 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,21 @@
11
# Zet-cmd
22

3-
[![License](https://img.shields.io/badge/license-Apache2-brightgreen.svg)](LICENSE)
4-
5-
## Install
3+
> A command line tool for managing a personal Zettelkasten
64
7-
This command can be installed as a standalone program or composed into a
8-
Bonzai command tree.
5+
This is a CLI tool for managing zet's or notes. It allows me to capture ideas and thoughts from the command line.
6+
GitHub is used as the "database" for note storage. This has the added benefit of being publicly available without
7+
the need for the CLI.
98

10-
Standalone
9+
These *zet's* are also available on my [blog](https://danielms.site/zet). I have written a [blog post](https://danielms.site/blog/github-actions-auto-publish-zettelkasten-notes/)
10+
about how I use GitHub Actions to automatically publish these notes.
1111

12-
```
13-
go install github.com/danielmichaels/zet-cmd/cmd/zet@latest
14-
```
15-
Composed
16-
17-
```go
18-
package zet
12+
[![License](https://img.shields.io/badge/license-Apache2-brightgreen.svg)](LICENSE)
1913

20-
import (
21-
Z "github.com/rwxrob/bonzai/z"
22-
"github.com/rwxrob/help"
23-
"github.com/danielmichaels/zet-cmd"
24-
)
14+
## Install
2515

26-
var Cmd = &Z.Cmd{
27-
Name: `zet`,
28-
Commands: []*Z.Cmd{help.Cmd, zet.Cmd},
29-
}
16+
```bash
17+
go install github.com/danielmichaels/zet-cmd/cmd/zet@latest
3018
```
31-
3219
## Requirements
3320

3421
`zet-cmd` must have a GitHub repository to push commits to named `zet`. For instance, my
@@ -49,28 +36,8 @@ On a new machine (but existing `zet` repo), you will need to `git clone` to the
4936
paths. Any `false` values or empty `Repo` entries will need to be rectified or your `zet-cmd` may
5037
not function as expected, or at all.
5138

52-
## Tab Completion
53-
54-
To activate bash completion just use the `complete -C` option from your
55-
`.bashrc` or command line. There is no messy sourcing required. All the
56-
completion is done by the program itself.
57-
58-
```
59-
complete -C zet zet
60-
```
61-
62-
If you don't have bash or tab completion check use the shortcut
63-
commands instead.
64-
65-
## Embedded Documentation
66-
67-
All documentation (like manual pages) has been embedded into the source
68-
code of the application. See the source or run the program with help to
69-
access it.
39+
### Inspiration
7040

71-
## Other Examples
41+
A lot of this was inspired by [rwxrob](https://github.com/rwxrob/)
7242

73-
* <https://github.com/rwxrob/cmd-zet> - with heavy inspiration
74-
* <https://github.com/danielmichaels/ds> - my personal Bonzai commander
75-
7643
[ghzet]: https://github.com/danielmichaels/zet

cmd.go

Lines changed: 0 additions & 37 deletions
This file was deleted.

cmd/zet/README.md

Lines changed: 0 additions & 6 deletions
This file was deleted.

cmd/zet/main.go

Lines changed: 68 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,71 @@
1-
// Copyright 2022-2024 zet-cmd Authors
2-
// SPDX-License-Identifier: Apache-2.0
3-
41
package main
52

6-
import "github.com/danielmichaels/zet-cmd"
3+
import (
4+
"fmt"
5+
"github.com/danielmichaels/zet-cmd"
6+
"github.com/danielmichaels/zet-cmd/internal/version"
7+
"os"
8+
9+
"github.com/alecthomas/kong"
10+
)
11+
12+
const appName = "zet"
13+
14+
type VersionFlag string
15+
16+
func (v VersionFlag) Decode(_ *kong.DecodeContext) error { return nil }
17+
func (v VersionFlag) IsBool() bool { return true }
18+
func (v VersionFlag) BeforeApply(app *kong.Kong, vars kong.Vars) error {
19+
fmt.Println(vars["version"])
20+
app.Exit(0)
21+
return nil
22+
}
23+
24+
type CLI struct {
25+
Version VersionFlag `help:"Print version information and quit" name:"version"`
26+
zet.Globals
27+
28+
// Commands
29+
Create zet.CreateCmd `cmd:"" aliases:"new" help:"Create a new zet"`
30+
Last zet.LastCmd `cmd:"" help:"Show the last created zet's isosec (location)'"`
31+
Edit zet.EditCmd `cmd:"" help:"Edit a zet"`
32+
Find zet.FindCmd `cmd:"" help:"Search for a zet title and retrieve any matching entry"`
33+
Check zet.CheckCmd `cmd:"" help:"Check zettelkasten for issues"`
34+
Tags zet.TagsCmd `cmd:"" help:"Search for a zet by tag and retrieve any entries with that tag"`
35+
Git zet.GitCmd `cmd:"" help:"Git operations for zettelkasten"`
36+
View zet.ViewCmd `cmd:"" help:"View supports both direct 'isosec' lookup's and keyword searches"`
37+
}
38+
39+
func run() error {
40+
ver := version.Get()
41+
if ver == "unavailable" {
42+
ver = "development"
43+
}
44+
cli := CLI{
45+
Version: VersionFlag(ver),
46+
}
47+
// Display help if no args are provided instead of an error message
48+
if len(os.Args) < 2 {
49+
os.Args = append(os.Args, "--help")
50+
}
751

8-
// tree grown from branch
9-
func main() { zet.Cmd.Run() }
52+
ctx := kong.Parse(&cli,
53+
kong.Name(appName),
54+
kong.Description(fmt.Sprintf("%s is a zettelkasten tool", appName)),
55+
kong.UsageOnError(),
56+
kong.ConfigureHelp(kong.HelpOptions{
57+
Compact: true,
58+
}),
59+
kong.DefaultEnvars(appName),
60+
kong.Vars{
61+
"version": string(cli.Version),
62+
})
63+
err := ctx.Run(cli.Globals)
64+
ctx.FatalIfErrorf(err)
65+
return nil
66+
}
67+
func main() {
68+
if err := run(); err != nil {
69+
os.Exit(1)
70+
}
71+
}

0 commit comments

Comments
 (0)