docbasecli

package module
v0.0.0-...-4fc5ce5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 20, 2022 License: MIT Imports: 19 Imported by: 0

README

docbase-cli

docbase.io の記事を操作するコマンドラインツール

Installation

goコマンド でのインストール

(Go 1.16以降) go install でバイナリをインストール

$ go install github.com/micheam/docbase-cli/cmd/docbase@latest

(Go 1.15 以前) go get でバイナリをインストール

$ go get github.com/micheam/docbase-cli/...
ソースコードからビルド
$ git clone github.com/micheam/docbase-cli
$ cd docbase-cli
$ make install

Usage

$ docbase [global options] command [command options] [arguments...]

Commands

view     show post title and body
list     Search and list posts on docbase.io
new      Create new post.
edit     edit specified post.
tags     Show tags of group
help, h  Shows a list of commands or help for one command

Global Options

--verbose, --vv       (default: false) [$DOCBASE_VERBOSE, $DOCBASE_DEBUG, $DEBUG]
--token ACCESS_TOKEN  ACCESS_TOKEN for docbase API [$DOCBASE_TOKEN]
--domain NAME         NAME on docbase.io [$DOCBASE_DOMAIN]
--help, -h            show help (default: false)
--version, -v         print the version (default: false)

License

MIT

Author

Michito Maeda https://github.com/micheam

Documentation

Overview

Package docbasecli は、CLI向けの各種機能を提供します

Index

Constants

View Source
const DefaultEditor = "vim"

DefaultEditor is vim because we're adults ;)

Variables

View Source
var DefaultPostOption = docbase.PostOption{
	Draft:  pointer.BoolPtr(true),
	Tags:   []string{},
	Scope:  "private",
	Groups: []int{},
}

DefaultPostOption メモ作成時のデフォルトオプション

View Source
var ErrNotFound = errors.New("no post found")

Functions

func CaptureInputFromEditor

func CaptureInputFromEditor(resolveEditor PreferredEditorResolver, file *os.File) ([]byte, error)

CaptureInputFromEditor opens a temporary file in a text editor and returns the written bytes on success or an error on failure. It handles deletion of the temporary file behind the scenes.

func CreatePost

func CreatePost(ctx context.Context, req CreatePostRequest, handler PostHandler) error

func GetPost

func GetPost(ctx context.Context, req GetPostRequest, handle PostHandler) error

func GetPreferredEditorFromEnvironment

func GetPreferredEditorFromEnvironment() string

GetPreferredEditorFromEnvironment returns the user's editor as defined by the `$EDITOR` environment variable, or the `DefaultEditor` if it is not set.

func IsTerminal

func IsTerminal(f *os.File) bool

func ListPosts

func ListPosts(ctx context.Context, req ListPostsRequest, handle PostCollectionHandler) error

func ListTags

func ListTags(ctx context.Context, req ListTagsRequest, presenter TagCollectionPresenter) error

func OpenBrowser

func OpenBrowser(_ context.Context, post docbase.Post) error

func OpenFileInEditor

func OpenFileInEditor(filename string, resolveEditor PreferredEditorResolver) error

OpenFileInEditor opens filename in a text editor.

func UpatePost

func UpatePost(ctx context.Context, req UpdatePostRequest, handle PostHandler) error

Types

type Config

type Config struct {
	AccessToken string
	Domain      string
	UserID      string
	Editor      string
}

func LoadConfig

func LoadConfig(r io.Reader) (*Config, error)

LoadConfig は、 Default 設定を読み込みます。

type ConfigMap

type ConfigMap map[string]Config

type CreatePostRequest

type CreatePostRequest struct {
	Domain string
	Title  string
	Body   io.Reader

	// Option メモ作成時のオプション
	// 省略した場合は DefaultPostOption が適用される
	Option *docbase.PostOption
}

type GetPostRequest

type GetPostRequest struct {
	ID     docbase.PostID
	Domain string
}

type ListPostsRequest

type ListPostsRequest struct {
	Query   *string
	Page    *int
	PerPage *int
	Domain  string
}

type ListTagsRequest

type ListTagsRequest struct {
	Domain string
}

type PostCollectionHandler

type PostCollectionHandler func(ctx context.Context, ps []docbase.Post, m docbase.Meta) error

define ResultHandlers

func BuildPostCollectionHandler

func BuildPostCollectionHandler(withMeta bool) (PostCollectionHandler, error)

type PostHandler

type PostHandler func(ctx context.Context, p docbase.Post) error

define ResultHandlers

func OutputPostBody

func OutputPostBody(out io.Writer) PostHandler

func OutputPostDetail

func OutputPostDetail(out io.Writer, n int) PostHandler

type PreferredEditorResolver

type PreferredEditorResolver func() string

PreferredEditorResolver is a function that returns an editor that the user prefers to use, such as the configured `$EDITOR` environment variable.

type TagCollectionPresenter

type TagCollectionPresenter func(ctx context.Context, tags []docbase.Tag) error

type UpdatePostRequest

type UpdatePostRequest struct {
	Domain string
	ID     docbase.PostID
	Body   io.Reader
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL