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
32 changes: 0 additions & 32 deletions .github/workflows/ci.yml

This file was deleted.

48 changes: 48 additions & 0 deletions .github/workflows/go_ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Go CI

on:
push:
branches: [main, migrate]
pull_request:
branches: ['**']

permissions:
contents: read

jobs:
affected-checks:
runs-on: ubuntu-latest
outputs:
matches: ${{ steps.filter.outputs['go'] || 'false' }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v2
id: filter
with:
filters: |
go:
- '**/*.go'
- 'go.mod'
- 'go.sum'
- '.github/workflows/go_ci.yml'

guard:
needs: affected-checks
if: ${{ needs.affected-checks.outputs.matches == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Check formatting
run: test -z "$(gofmt -l .)"
- name: Vet
run: go vet ./...
- name: Test
run: go test ./...
- name: Lint
uses: golangci/golangci-lint-action@v8
with:
# Keep in sync with .mise.toml for local reproducibility.
version: v2.12.2
34 changes: 0 additions & 34 deletions .github/workflows/wc_ci.yml

This file was deleted.

7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@
.log

# Testing dummy files
test/dummy_log_dir/*
test/dummy_log_dir/*
# Obsidian editor config
docs/.obsidian/

# Go build artifacts
/sava
10 changes: 10 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: "2"

linters:
settings:
errcheck:
# CLI output to stdout/stderr: write errors are not actionable.
exclude-functions:
- fmt.Fprint
- fmt.Fprintf
- fmt.Fprintln
4 changes: 3 additions & 1 deletion .mise.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
[tools]
deno = "2.4.3"
go = "1.26.4"
# Keep in sync with .github/workflows/go_ci.yml
golangci-lint = "2.12.2"
13 changes: 0 additions & 13 deletions .vscode/launch.json

This file was deleted.

3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

76 changes: 49 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# nippo-cli (`sava`)

## Motivation / Background
エンジニアはほとんどの時間を console をみて過ごしている.
作業時間やちょっとした思考をメモしておくのに他ツールとのスイッチはコストが高いと考えます.
Expand All @@ -8,48 +10,68 @@
- cli ツール作りたい
- 独り言メモツールしたい(日報補助ツール)

## command
```
sava add 'message'
```

構想は gist に
https://gist.github.com/rn404/decf010fc48d7d8688116af0f4427b44

### Objects
* LogFile > Log > Item (MemoItem, TaskItem)
## Install

### Architecture
* Command -- Feature -- LogFile
* Feature -- LogFile
* LogFileInterface
* Command -- Feature
* Models(Class instance)
```
go install github.com/rn404/nippo-cli/cmd/sava@latest
```

## Usage

## Usage (developer)
```
# command help
deno run src/sava.ts

# Add todo item
deno run -A src/sava.ts add <message>

# Finish todo item
deno run -A src/sava.ts end <hash>
sava add <message>

# Add memo item
deno run -A src/sava.ts add -m <message>
sava add -m <message>

# Finish todo item
sava end <hash>

# Delete item
deno run -A src/sava.ts del <hash>
sava del <hash>

# List today's log items
sava list

# List items of a specific day / all log files / summaries
sava list <yyyy-MM-dd>
sava list -a
sava list -s
sava list -a -s

# List log items
deno run -A src/sava.ts list
# Delete logs past the storage period (30 days)
sava clear

# Delete all logs (with confirmation; use -y to skip prompts)
sava clear -a
```

### Formatter
ログは `~/.log/sava/<yyyy-MM-dd>.json` に 1 日 1 ファイルで保存されます.

### Objects
* LogFile > Log > Item (Task, Memo)

### Architecture
* cmd/sava -- internal/command -- internal/{logfile, log, view} -- internal/model

## Development

```
./scripts/format.sh
# Run from source
go run ./cmd/sava <command>

# Test / format / lint
go test ./...
gofmt -l .
go vet ./...
golangci-lint run # version is pinned in .mise.toml (mise install)
```

## History

もともと Deno / TypeScript で実装されていましたが、Go に移行しました.
経緯は `docs/go-migration-plan.md` を参照してください.
78 changes: 78 additions & 0 deletions cmd/sava/commands.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package main

import (
"github.com/spf13/cobra"

"github.com/rn404/nippo-cli/internal/command"
"github.com/rn404/nippo-cli/internal/logfile"
)

func newAddCommand() *cobra.Command {
var memo bool
cmd := &cobra.Command{
Use: "add <contents>",
Short: "Add contents to nippo log.",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return command.Add(logfile.Dir(), args[0], memo)
},
}
cmd.Flags().BoolVarP(&memo, "memo", "m", false, "Add contents like memo item.")
return cmd
}

func newEndCommand() *cobra.Command {
return &cobra.Command{
Use: "end <hash>",
Short: "end to task.",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return command.End(cmd.OutOrStdout(), logfile.Dir(), args[0])
},
}
}

func newDelCommand() *cobra.Command {
return &cobra.Command{
Use: "del <hash>",
Short: "delete task.",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return command.Del(logfile.Dir(), args[0])
},
}
}

func newListCommand() *cobra.Command {
opts := command.ListOptions{}
cmd := &cobra.Command{
Use: "list [date]",
Short: "list all logs.",
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 1 {
opts.Date = args[0]
}
return command.List(cmd.OutOrStdout(), cmd.InOrStdin(), logfile.Dir(), opts)
},
}
cmd.Flags().BoolVarP(&opts.All, "all", "a", false, "show all logs")
cmd.Flags().BoolVarP(&opts.Stat, "stat", "s", false, "show summary of list")
cmd.Flags().BoolVarP(&opts.Yes, "yes", "y", false, "skip confirmation prompts")
return cmd
}

func newClearCommand() *cobra.Command {
var all, yes bool
cmd := &cobra.Command{
Use: "clear",
Short: "delete log",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return command.Clear(cmd.OutOrStdout(), cmd.InOrStdin(), logfile.Dir(), all, yes)
},
}
cmd.Flags().BoolVarP(&all, "all", "a", false, "clear all logs")
cmd.Flags().BoolVarP(&yes, "yes", "y", false, "skip confirmation prompts")
return cmd
}
42 changes: 42 additions & 0 deletions cmd/sava/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package main

import (
"fmt"
"os"

"github.com/spf13/cobra"
)

const appName = "sava"

// version is overridable at build time:
// go build -ldflags "-X main.version=vX.Y.Z"
var version = "v0.1.0"

func main() {
root := newRootCommand()
if err := root.Execute(); err != nil {
fmt.Fprintf(os.Stderr, "%s: %v\n", appName, err)
os.Exit(1)
}
}

func newRootCommand() *cobra.Command {
root := &cobra.Command{
Use: appName,
Short: "A memo tool to support daily reports",
Version: version,
SilenceUsage: true,
SilenceErrors: true,
}

root.AddCommand(
newAddCommand(),
newEndCommand(),
newDelCommand(),
newListCommand(),
newClearCommand(),
)

return root
}
Loading
Loading