Skip to content

Commit

Permalink
Merge pull request #13 from ikura-hamu/dep/use_cobra
Browse files Browse the repository at this point in the history
cobraを使う
  • Loading branch information
ikura-hamu committed Jul 30, 2024
2 parents 1c1b883 + 18fa7b3 commit 332a6da
Show file tree
Hide file tree
Showing 22 changed files with 664 additions and 384 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: "CI"

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: ./go.mod

- name: Install dependencies
run: go mod download

- name: Generate
run: go generate ./...

- name: Build
run: go build -v ./...

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: ./go.mod

- name: Install dependencies
run: go mod download

- name: Generate
run: go generate ./...

- name: Test
run: go test -v -race ./...

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: ./go.mod

- name: Install dependencies
run: go mod download

- name: Generate
run: go generate ./...

- name: Lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.59.1
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ q
.env

dist/
**/mock

.task
Empty file added .golangci.yaml
Empty file.
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"go.lintTool": "golangci-lint",
"go.lintFlags": [
"--fast"
]
}
18 changes: 0 additions & 18 deletions Makefile

This file was deleted.

85 changes: 38 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,39 +54,34 @@ unzip q-cli_{{OS}}_{{architecture}}.zip

#### 環境変数の場合

`Q_WEBHOOK_HOST`: traQのドメイン
`Q_WEBHOOK_ID`: traQのWebhook ID
`Q_WEBHOOK_SECRET`: traQのWebhook シークレット

#### 設定ファイルを使う場合

以下のような`config.json`を用意します。
以下のような`.q-cli.yml`を用意します。

```json:config.json
{
"webhook_id": "{{traQのWebhook ID}}",
"webhook_secret": "{{traQのWebhookシークレット}}"
}
```json:.q-cli.yml
webhook_host: "{{traQのドメイン}}"
webhook_id: "{{traQのWebhook ID}}"
webhook_secret: "{{traQのWebhookシークレット}}"
```

それを適切なディレクトリに配置します。以下を参考にして配置してください。(Goの`os.UserConfigDir()`を使用しています。)

> UserConfigDir returns the default root directory to use for user-specific configuration data. Users should create their own application-specific subdirectory within this one and use that.
>
> On Unix systems, it returns \$XDG_CONFIG_HOME as specified by https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html if non-empty, else \$HOME/.config. On Darwin, it returns \$HOME/Library/Application Support. On Windows, it returns %AppData%. On Plan 9, it returns $home/lib.
>
> If the location cannot be determined (for example, $HOME is not defined), then it will return an error.
このファイルをホームディレクトリに配置します。

## Usage

```txt
Usage of q:
q [option] [message]
-c string
Send message as code block. Specify the language name (e.g. go, python, shell)
-h Print this message
-i Interactive mode
-s Accept input from stdin
-v Print version
Usage:
q [message] [flags]
Flags:
-c, --code Send message with code block
--config string config file (default is $HOME/.q-cli.yaml)
-h, --help help for q
-l, --lang string Code block language
-v, --version Print version information and quit
```

```sh
Expand All @@ -106,55 +101,51 @@ traQに「Hello World」と投稿されます。
---

```sh
q -i
```

```txt
q [1]: 1行目
q [1]: 2行目
q [1]:
q [2]:
q
```

`-i` オプションを使用すると、ターミナルのように連続して、また、複数行のメッセージを送信できます(interactive mode)。改行では送信されず、`Ctrl-D`を入力すると送信されます。この例では、

```txt
1行目
2行目
```

のようになります。
メッセージが何もない場合は、標準入力からテキストを受け取り、投稿します。`EOF`(`Ctrl-D`)を受け取るまで投稿を待ちます。

以下のようにしてファイルの中身を投稿できます。

また、何も入力されていない状態で`Ctrl-D`を入力するとinteractive modeを抜けられます。
```sh
q < a.txt
```

---

```sh
echo foo | q -s
q -c text
```

```txt
foo
````md
```
text
```
````

`-s`オプションを使用すると、標準入力から値を受け取り、それをそのままメッセージとして投稿できます。機密情報を間違って投稿しないよう気を付けてください
`--code`(`-c`)オプションを使用すると、コードブロックとして投稿できます

---
`--lang`(`-l`)オプションで指定した値が最初の` ``` `の後に追加され、traQ上で適切なシンタックスハイライトが付きます。

```sh
q -c go package main
q -c -l go < main.go
```

````md
````txt
```go
package main
```
````

`-c`オプションを使用すると、コードブロックとして投稿できます。オプションで指定した値が最初の` ``` `の後に追加され、traQ上で適切なシンタックスハイライトが付きます。値は必ず指定しなくてはいけません。
上の`-s`オプションと組み合わせるとファイルの中身をきれいにtraQに投稿できます。
import "fmt"
```sh
cat main.go | q -s -c go
func main() {
fmt.Println("Hello, world")
}
```
````
24 changes: 24 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# https://taskfile.dev

version: "3"

silent: true

tasks:
test:
cmds:
- go test -v -race ./...

generate:
cmds:
- go generate ./...
aliases:
- gen
generates:
- ./**/mock/*.go
sources:
- ./internal/*/*.go

build:
cmds:
- go build -o ./bin/ -ldflags "-s -w" .
Loading

0 comments on commit 332a6da

Please sign in to comment.