Documentation
¶
Overview ¶
Package notes is a library which consists notes command.
https://github.com/rhysd/notes-cli/tree/master/cmd/notes
This library is for using notes command programmatically from Go program. It consists structs which represent each subcommands.
1. Create Config instance with NewConfig 2. Create an instance of subcommand you want to run with config 3. Run it with .Do() method. It will return an error if some error occurs
import (
"bytes"
"fmt"
"github.com/rhysd/notes-cli"
"os"
"strings"
)
var buf bytes.Buffer
// Create user configuration
cfg, err := notes.NewConfig()
if err != nil {
panic(err)
}
// Prepare `notes list` command
cmd := ¬es.ListCmd{
Config: cfg,
Relative: true,
Out: &buf
}
// Runs the command
if err := cmd.Do(); err != nil {
fmt.Fprintln(os.Stdout, err)
}
paths := strings.Split(strings.Trim(buf.String(), "\n"), "\n")
fmt.Println("Note paths:", paths)
For usage of `notes` command, please read README of the repository.
Index ¶
- Variables
- func WalkNotes(cat string, cfg *Config, pred func(path string, note *Note) error) error
- type CategoriesCmd
- type Cmd
- type Config
- type ConfigCmd
- type Git
- func (git *Git) AddAll() error
- func (git *Git) Command(subcmd string, args ...string) *exec.Cmd
- func (git *Git) Commit(msg string) error
- func (git *Git) Exec(subcmd string, args ...string) (string, error)
- func (git *Git) Init() error
- func (git *Git) Push(remote, branch string) error
- func (git *Git) TrackingRemote() (string, string, error)
- type ListCmd
- type NewCmd
- type Note
- type SaveCmd
- type SelfupdateCmd
- type TagsCmd
Constants ¶
This section is empty.
Variables ¶
var Version = "1.2.0"
Version is version string of notes command. It conforms semantic versioning
Functions ¶
func WalkNotes ¶
WalkNotes walks all notes with given predicate. If given category string is an empty, it traverses notes of all categories. Otherwise, it only traverses notes of the specified categories. When the category does not exist, this function returns an error. When given predicate returns an error or when loading a note fails, this function stops traversing and immediately returns the error
Types ¶
type CategoriesCmd ¶
type CategoriesCmd struct {
Config *Config
// Out is a writer to write output of this command. Kind of stdout is expected
Out io.Writer
// contains filtered or unexported fields
}
CategoriesCmd represents `notes categories` command. Each public fields represent options of the command. Out field represents where this command should output.
func (*CategoriesCmd) Do ¶
func (cmd *CategoriesCmd) Do() error
Do runs `notes categories` command and returns an error if occurs
type Cmd ¶
type Cmd interface {
Do() error
// contains filtered or unexported methods
}
Cmd is an interface for subcommands of notes command
type Config ¶
type Config struct {
// HomePath is a file path to directory of home of notes command. If $NOTES_CLI_HOME is set, it is used.
// Otherwise, notes-cli directory in XDG data directory is used. This directory is automatically created
// when config is created
HomePath string
// GitPath is a file path to `git` executable. If $NOTES_CLI_GIT is set, it is used.
// Otherwise, `git` is used by default. This is optional and can be empty. When empty, some command
// and functionality which require Git don't work
GitPath string
// EditorPath is a file path to executable of your favorite editor. If $NOTES_CLI_EDITOR is set, it is used.
// Otherwise, this value will be empty. When empty, some functionality which requires an editor to open note
// doesn't work
EditorPath string
}
Config represents user configuration of notes command
type ConfigCmd ¶
type ConfigCmd struct {
Config *Config
// Name is a name of configuration. Must be one of "", "home", "git" or "editor"
Name string
// Out is a writer to write output of this command. Kind of stdout is expected
Out io.Writer
// contains filtered or unexported fields
}
ConfigCmd represents `notes config` command. Each public fields represent options of the command. Out field represents where this command should output.
type Git ¶
type Git struct {
// contains filtered or unexported fields
}
Git represents Git command for specific repository
func NewGit ¶
NewGit creates Git instance from Config value. Home directory is assumed to be a root of Git repository
func (*Git) Command ¶
Command returns exec.Command instance which runs given Git subcommand with given arguments
type ListCmd ¶
type ListCmd struct {
Config *Config
// Full is a flag equivalent to --full
Full bool
// Category is a regex string equivalent to --cateogry
Category string
// Tag is a regex string equivalent to --tag
Tag string
// Relative is a flag equivalent to --relative
Relative bool
// Oneline is a flag equivalent to --oneline
Oneline bool
// Tag is a string indicating how to sort the list. This value is equivalent to --sort option
SortBy string
// Edit is a flag equivalent to --edit
Edit bool
// Out is a writer to write output of this command. Kind of stdout is expected
Out io.Writer
// contains filtered or unexported fields
}
ListCmd represents `notes list` command. Each public fields represent options of the command Out field represents where this command should output.
type NewCmd ¶
type NewCmd struct {
Config *Config
// Category is a category name of the new note. This must be a name allowed for directory name
Category string
// Filename is a file name of the new note
Filename string
// Tags is a comma-separated string of tags of the new note
Tags string
// NoInline is a flag equivalent to --no-inline-input
NoInline bool
// contains filtered or unexported fields
}
NewCmd represents `notes new` command. Each public fields represent options of the command
type Note ¶
type Note struct {
// Config is a configuration of notes command which was created by NewConfig()
Config *Config
// Category is a category string. It must not be empty
Category string
// Tags is tags of note. It can be empty and cannot contain comma
Tags []string
// Created is a datetime when note was created
Created time.Time
// File is a file name of the note
File string
// Title is a title string of the note. When the note is not created yet, it may be empty
Title string
}
Note represents a note stored on filesystem or will be created
func LoadNote ¶
LoadNote reads note file from given path, parses it and creates Note instance. When given file path does not exist or when the file does note contain mandatory metadata ('Category', 'Tags' and 'Created'), this function returns an error
func NewNote ¶
NewNote creates a new note instance with given parameters and configuration. Category and file name cannot be empty. If given file name lacks file extension, it automatically adds ".md" to file name.
func (*Note) Create ¶
Create creates a file of the note. When title is empty, file name omitting file extension is used for it. This function will fail when the file is already existing.
func (*Note) Open ¶
Open opens the note using an editor command user set. When user did not set any editor command with $NOTES_CLI_EDITOR, this method fails. Otherwise, an editor process is spawned with argument of path to the note file
func (*Note) RelFilePath ¶
RelFilePath returns the relative file path of the note from home directory
type SaveCmd ¶
type SaveCmd struct {
Config *Config
// Message is a message of Git commit which will be created to save notes. If this value is empty,
// automatically generated message will be used.
Message string
// contains filtered or unexported fields
}
SaveCmd represents `notes save` command. Each public fields represent options of the command
type SelfupdateCmd ¶ added in v1.1.0
type SelfupdateCmd struct {
// Dry is a flag equivalent to --dry
Dry bool
// Slug is a "user/repo" string where releases are put. This field is useful when you forked
// notes-cli into your own repository.
Slug string
// Out is a writer to write output of this command. Kind of stdout is expected
Out io.Writer
// contains filtered or unexported fields
}
SelfupdateCmd represents `notes selfupdate` subcommand.
func (*SelfupdateCmd) Do ¶ added in v1.1.0
func (cmd *SelfupdateCmd) Do() error
Do method checks the newer version binary. If new version is available, it updates myself with the latest binary.
type TagsCmd ¶
type TagsCmd struct {
Config *Config
// Category is a category name of tags. If this value is empty, tags of all categories will be output
Category string
// Out is a writer to write output of this command. Kind of stdout is expected
Out io.Writer
// contains filtered or unexported fields
}
TagsCmd represents `notes tags` command. Each public fields represent options of the command Out field represents where this command should output.
