clinote

package module
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2019 License: GPL-3.0 Imports: 17 Imported by: 0

README

Build Status Go Report Card Release

CLInote

CLInote is a command line client for Evernote inspired by geeknote.

CLInote allows you to:

  • Create notes
  • Send the note content to stdout
  • Edit notes in your $EDITOR
  • Create new notebooks
  • Search for notes

Installation

From source:

go get -v github.com/TcM1911/clinote/cmd

Download pre-build binary from the release page.

Authorize to Evernote via OAuth

Before you can use any features, you need to authorize CLInote to access youre notes. To authorize run the command:

clinote user login

If you have your default browser defined in the $BROWSER environment variable, CLInote will open the link in your default browser.

Authenticating with the Evernote Cloud API using Tokens

Before you can use any features, you need to generate an API token for CLInote to use. Generate a token here. To add a new set of user credentials, run the command:

clinote user add

To add sandbox credentials, run the command:

clinote user add --sandbox

You can list the credentials with the command:

clinote user list

To set a credential as active use the command clinote user set credential "index". For example:

clinote user set credential 1

Create a new note

A new note can be created with the command shown below. A title needs to be given for the note. If no notebook is given, the default notebook will be used. The new note can be open in the $EDITOR by using the edit flag.

clinote note new --title "note title" [--notebook "notebook name"] [--edit]

Edit note

Notes can be edited using the edit command. If no flags are set, the note is opened with the editor defined by the environment variable $EDITOR. The first line will be used as the note title and the rest is encoded as the note content.

To change to title, the title flag can be used.

The note can be moved to another notebook by defining the new notebook with the notebook flag.

clinote note edit "note title" [--title "new note title"] [--notebook "new notebook"]
Recover note that failed to save

If clinote fails to save a note, the note can be reopened for editing using the --recover flag.

clinote note edit --recover

Show note content

You can send the note content to the standard out with the command below:

clinote note "note title"

Remove a note

Delete moves the note into the trash. The note may still be undeleted, unless it is expunged. To expunge the note you need to use the official client or the web client.

clinote note delete "note title"

Search for notes

To search for notes, use the list command as shown below.

clinote note list [--count 20] [--search "search term"] [--notebook "notebook name"]

The search term flag can be used to define a search term to be used. The search can be restricted to a notebook by using the notebook flag.

Count can be used to restrict the maximum number of notes returned.

If no search term is given, a wild card search will be used. The notes will be sorted by the modified time.

View/edit/remove notes returned in the search list

You can view, edit, or remove notes returned by the list command using the note's index number. For example to show the content of the first note in the list, use the following command:

clinote note 1

To remove the 5th note in the list, use:

clinote note delete 5

Create a new notebook

To create a new notebook, use the command below:

clinote notebook new "notebook name" [--default] [--stack "Stack name"]

Edit a notebook

To edit a notebook use this command:

clinote notebook edit "notebook name" [--name "new notebook name"] [--stack "new stack"]

List all notebooks

To list all notebooks, use the notebook list command:

clinote notebook list

Documentation

Index

Constants

View Source
const (
	// DefaultClientOptions creates a client with default options.
	DefaultClientOptions ClientOption = 0
	// EvernoteSandbox tells the client to use Evernote's sandbox instead of production.
	EvernoteSandbox = 1 << iota
	// MemoryBasedCacheFile for using a ram based file for editing.
	MemoryBasedCacheFile
	// VimEditer for using Vim as the editor.
	VimEditer
)
View Source
const (
	// DefaultNoteOption will display or edit the note with default options.
	DefaultNoteOption NoteOption = 0
	// RawNote option will display or edit the note in it's raw format.
	RawNote = 1 << iota
	// UseRecoveryPointNote should be used to signal that the user wants to
	// reopen the note that the note store failed to save.
	UseRecoveryPointNote
)
View Source
const (
	// XMLHeader is the header that needs to added to the note content.
	XMLHeader = `<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">`
)

Variables

View Source
var (
	// ErrNoMatchingCredentialFound is returned if no matching credential is found.
	ErrNoMatchingCredentialFound = errors.New("no matching credential found")
	// ErrNegativeIndex is returned if index is negative
	ErrNegativeIndex = errors.New("index negative")
	// ErrIndexToBig is returned if index is greater than the list.
	ErrIndexToBig = errors.New("index greater than the array")
)
View Source
var (
	// NoteFilterOrderCreated sorts the notes by create time.
	NoteFilterOrderCreated = int32(1)
	// NoteFilterOrderUpdated sorts the notes by update time.
	NoteFilterOrderUpdated = int32(2)
	// NoteFilterOrderRelevance sorts the notes by relevance.
	NoteFilterOrderRelevance = int32(3)
	// NoteFilterOrderSequenceNumber sorts the notes by sequence number.
	NoteFilterOrderSequenceNumber = int32(4)
	// NoteFilterOrderTitle sorts the notes by title.
	NoteFilterOrderTitle = int32(5)
)
View Source
var (
	// ErrNoNotebookFound is returned if no matching notebook was found.
	ErrNoNotebookFound = errors.New("no notebook found")
	// ErrNoNotebookCached is returned when trying to update a notebook
	// that hasn't been pulled from the server.
	ErrNoNotebookCached = errors.New("no notebook found")
)
View Source
var (
	// DefaultNotebookCacheTime is the default time limit for when the
	// list is considered outdated.
	DefaultNotebookCacheTime = 24 * time.Hour
)
View Source
var (
	// ErrNoEditorFound is returned if no editor was found.
	ErrNoEditorFound = errors.New("no editor found")
)
View Source
var (
	// ErrNoNoteFound is returned if search resulted in no notes found.
	ErrNoNoteFound = errors.New("no note found")
)

Functions

func AddNewCredential added in v0.5.0

func AddNewCredential(store UserCredentialStore, name, secret string, credType CredentialType) error

AddNewCredential creates and add a new credential to the store.

func ChangeTitle

func ChangeTitle(db Storager, ns NotestoreClient, old, new string) error

ChangeTitle changes the note's title.

func CreateAndEditNewNote added in v0.5.0

func CreateAndEditNewNote(client *Client, note *Note, opts NoteOption) error

CreateAndEditNewNote creates a new note and opens it in the client's editor. Once the editor has been closed, the note is saved to the notestore.

func CreateNotebook

func CreateNotebook(ns NotestoreClient, notebook *Notebook, defaultNotebook bool) error

CreateNotebook creates a new notebook.

func DeleteNote

func DeleteNote(db Storager, ns NotestoreClient, title, notebook string) error

DeleteNote moves a note from the notebook to the trash can.

func EditNote added in v0.5.0

func EditNote(client *Client, title string, opts NoteOption) error

EditNote opens the editor so the user can edit the note. Once the user closes the editor, the note is saved to the notestore.

func MoveNote

func MoveNote(db Storager, ns NotestoreClient, noteTitle, notebookName string) error

MoveNote moves the note to a new notebook.

func RemoveCredential added in v0.5.0

func RemoveCredential(store UserCredentialStore, name string) error

RemoveCredential removes the first credential with the matching name.

func RemoveCredentialByIndex added in v0.5.0

func RemoveCredentialByIndex(store UserCredentialStore, index int) error

RemoveCredentialByIndex removes the credential at the index provided.

func SaveChanges

func SaveChanges(ns NotestoreClient, n *Note, opts NoteOption) error

SaveChanges updates the changes to the note on the server.

func SaveNewNote

func SaveNewNote(ns NotestoreClient, n *Note, raw bool) error

SaveNewNote pushes the new note to the server.

func UpdateNotebook

func UpdateNotebook(db Storager, ns NotestoreClient, name string, notebook *Notebook) error

UpdateNotebook updates the notebook.

func WriteCredentialListing added in v0.5.0

func WriteCredentialListing(w io.Writer, creds []*Credential)

WriteCredentialListing creates and writes a credential listing table using the writer.

func WriteCredentialListingWithSecret added in v0.5.0

func WriteCredentialListingWithSecret(w io.Writer, creds []*Credential)

WriteCredentialListingWithSecret creates and writes a credential listing table using the writer.

func WriteNote added in v0.5.0

func WriteNote(w io.Writer, n *Note, opts NoteOption) error

WriteNote writes the note using the provided writer.

func WriteNoteListing added in v0.5.0

func WriteNoteListing(w io.Writer, ns []*Note, nbs []*Notebook)

WriteNoteListing creates and writes a note listing table using the writer.

func WriteNotebookListing added in v0.5.0

func WriteNotebookListing(w io.Writer, nbs []*Notebook)

WriteNotebookListing creates and writes a notebook listing table using the writer.

func WriteSettingsListing added in v0.5.0

func WriteSettingsListing(w io.Writer, vals, args, desc []string)

WriteSettingsListing writes the settings table to writer.

Types

type CacheFile added in v0.5.0

type CacheFile interface {
	io.ReadWriteCloser
	FilePath() string
	ReOpen() error
	CloseAndRemove() error
}

CacheFile has the note content written and the user edits the content in the CacheFile to update the note's content.

type Client added in v0.5.0

type Client struct {
	// Config is the systems configuration
	Config Configuration
	// Store is the storage client
	Store Storager
	// Notestore is a client to interact with the note store.
	NoteStore NotestoreClient
	// Editor is the editor.
	Editor Editer
	// contains filtered or unexported fields
}

Client is a client for all note operations.

func NewClient added in v0.5.0

func NewClient(config Configuration, store Storager, ns NotestoreClient, opts ClientOption) *Client

NewClient creates a new Client struct.

func (*Client) Edit added in v0.5.0

func (c *Client) Edit(file CacheFile) error

Edit edits the cache file using the client's editor.

func (*Client) NewCacheFile added in v0.5.0

func (c *Client) NewCacheFile(filename string) (CacheFile, error)

NewCacheFile creates a new cache file for editing.

type ClientOption added in v0.5.0

type ClientOption int32

ClientOption is an bit mask of options for the client.

type Configuration

type Configuration interface {
	io.Closer
	// GetConfigFolder returns the folder used to store configurations.
	GetConfigFolder() string
	// GetCacheFolder returns the cache folder.
	GetCacheFolder() string
	// Store returns the backend storage.
	Store() Storager
	// UserStore returns the user storage.
	UserStore() UserCredentialStore
}

Configuration is the interface for a configuration struct.

type Credential added in v0.5.0

type Credential struct {
	// Name is the user given name for the credential.
	Name string
	// Secret is used to authenticate to the note store.
	Secret string
	// CredType is used to identify credential type.
	CredType CredentialType
}

Credential is a struct that holds credential information.

func GetAllCredentials added in v0.5.0

func GetAllCredentials(store UserCredentialStore) ([]*Credential, error)

GetAllCredentials returns all the credentials in the store.

func GetCredential added in v0.5.0

func GetCredential(store UserCredentialStore, index int) (*Credential, error)

GetCredential returns the credential with the matching index.

type CredentialType added in v0.5.0

type CredentialType uint8

CredentialType is a type of credential. Used to identify which backend to use

const (
	// EvernoteCredential is used for credentials that can authenticate with Evernote.
	EvernoteCredential CredentialType = iota
	// EvernoteSandboxCredential is used for credentials that can authenticate with
	// Evernote's sandbox server.
	EvernoteSandboxCredential
)

func (CredentialType) String added in v0.5.0

func (c CredentialType) String() string

type DefaultConfig

type DefaultConfig struct {
	// DB is the backend storage for the client.
	DB Storager
	// UDB is the backend storage for user credentials.
	UDB UserCredentialStore
}

DefaultConfig uses shared config and cache folder with other instances of DefaultConfig structs.

func (*DefaultConfig) Close

func (c *DefaultConfig) Close() error

Close closes the BoltDB handler.

func (*DefaultConfig) GetCacheFolder

func (*DefaultConfig) GetCacheFolder() string

GetCacheFolder returns the folder used to cache.

func (*DefaultConfig) GetConfigFolder

func (*DefaultConfig) GetConfigFolder() string

GetConfigFolder returns the folder used to store configurations.

func (*DefaultConfig) Store

func (c *DefaultConfig) Store() Storager

Store returns a handler to BoltDB.

func (*DefaultConfig) UserStore added in v0.5.0

func (c *DefaultConfig) UserStore() UserCredentialStore

UserStore returns a handler to BoltDB.

type Editer added in v0.5.0

type Editer interface {
	// Edit allows the user to edit the note.
	Edit(CacheFile) error
}

Editer is an object that can edit notes.

type EnvEditor added in v0.5.0

type EnvEditor struct{}

EnvEditor opens the note the note using the program defined in the environment variable $EDITOR.

func (*EnvEditor) Edit added in v0.5.0

func (e *EnvEditor) Edit(file CacheFile) error

Edit opens the CacheFile with the editor defined in $EDITOR.

type FileCacheFile added in v0.5.0

type FileCacheFile struct {
	// contains filtered or unexported fields
}

FileCacheFile implements the CacheFile interface and uses a temporary file for storing the data on disk.

func (*FileCacheFile) Close added in v0.5.0

func (f *FileCacheFile) Close() error

Close closes the file. This should be called before the file is edited by the editor.

func (*FileCacheFile) CloseAndRemove added in v0.5.0

func (f *FileCacheFile) CloseAndRemove() error

CloseAndRemove closes the file and removes it.

func (*FileCacheFile) FilePath added in v0.5.0

func (f *FileCacheFile) FilePath() string

FilePath returns the absolute path to the temporary file.

func (*FileCacheFile) ReOpen added in v0.5.0

func (f *FileCacheFile) ReOpen() error

ReOpen opens the file again after it's been closed. This should be called after the file has been edited.

func (*FileCacheFile) Read added in v0.5.0

func (f *FileCacheFile) Read(p []byte) (n int, err error)

Read returns content from the file.

func (*FileCacheFile) Write added in v0.5.0

func (f *FileCacheFile) Write(p []byte) (n int, err error)

Write adds content to the file.

type MemoryCacheFile added in v0.5.0

type MemoryCacheFile struct {
	// contains filtered or unexported fields
}

MemoryCacheFile is a memory based representation of a cache file.

func (*MemoryCacheFile) Close added in v0.5.0

func (m *MemoryCacheFile) Close() error

Close handles the close call.

func (*MemoryCacheFile) CloseAndRemove added in v0.5.0

func (m *MemoryCacheFile) CloseAndRemove() error

CloseAndRemove deletes the named FIFO pipe.

func (*MemoryCacheFile) FilePath added in v0.5.0

func (m *MemoryCacheFile) FilePath() string

FilePath returns the path to the FIFO pipe that should be used to send and receive data to and from the Editer.

func (*MemoryCacheFile) ReOpen added in v0.5.0

func (m *MemoryCacheFile) ReOpen() error

ReOpen handles the ReOpen call.

func (*MemoryCacheFile) Read added in v0.5.0

func (m *MemoryCacheFile) Read(p []byte) (n int, err error)

Read returns bytes from the memory buffer.

func (*MemoryCacheFile) Write added in v0.5.0

func (m *MemoryCacheFile) Write(p []byte) (n int, err error)

Write adds bytes to the memory buffer.

type Note

type Note struct {
	// Title is the note tile.
	Title string
	// GUID is the unique identifier.
	GUID string
	// Body contains the body of the note.
	Body string `xml:",innerxml"`
	// MD is a Markdown representation of the note body.
	MD string
	// Deleted is set true if the note is marked for deletion.
	Deleted bool
	// Notebook the note belongs to.
	Notebook *Notebook
	// Created
	Created int64
	// Updated
	Updated int64
}

Note is the structure of an Evernote note.

func FindNotes

func FindNotes(ns NotestoreClient, filter *NoteFilter, offset int, count int) ([]*Note, error)

FindNotes searches for notes.

func GetNote

func GetNote(db Storager, ns NotestoreClient, title, notebook string) (*Note, error)

GetNote gets the note metadata in the notebook from the server. If the notebook is an empty string, the first matching note will be returned.

func GetNoteWithContent

func GetNoteWithContent(db Storager, ns NotestoreClient, title string) (*Note, error)

GetNoteWithContent returns the note with content from the user's notestore.

func (*Note) Hash added in v0.5.0

func (n *Note) Hash(raw bool) []byte

Hash returns the hash for the note. If raw equals true, the raw content is used in the hash. Otherwise, the MD content is used.

type NoteFilter

type NoteFilter struct {
	// NotebookGUID is the GUID for the notebook to limit the search to.
	NotebookGUID string
	// Words can be a search string or note title.
	Words string
	// Order
	Order int32
}

NoteFilter is the search filter for notes.

type NoteOption added in v0.5.0

type NoteOption int32

NoteOption are used for options around notes.

type Notebook

type Notebook struct {
	// Name is the notebook's name
	Name string
	// GUID is the notebook's GUID.
	GUID string
	// Stack is the stack that the notebook belongs too.
	Stack string
}

Notebook is a struct for the notebook.

func FindNotebook

func FindNotebook(db Storager, ns NotestoreClient, name string) (*Notebook, error)

FindNotebook gets the notebook matching with the name. If no notebook is found, nil is returned.

func GetNotebook

func GetNotebook(ns NotestoreClient, guid string) (*Notebook, error)

GetNotebook returns a notebook from the user's notestore.

func GetNotebooks

func GetNotebooks(db Storager, ns NotestoreClient, forceSync bool) ([]*Notebook, error)

GetNotebooks returns all the user's notebooks.

type NotebookCacheList

type NotebookCacheList struct {
	// Notebooks is the list of notebooks.
	Notebooks []*Notebook
	// Timestamp of when the list was created.
	Timestamp time.Time
	// Limit is the until the list outdated.
	Limit time.Duration
}

NotebookCacheList is a list of cached notebooks.

func NewNotebookCacheList

func NewNotebookCacheList(notebooks []*Notebook) *NotebookCacheList

NewNotebookCacheList creates a cache list with the default expiration limit.

func NewNotebookCacheListWithLimit

func NewNotebookCacheListWithLimit(notebooks []*Notebook, limit time.Duration) *NotebookCacheList

NewNotebookCacheListWithLimit creates a new cache list with the given expiration limit.

func (*NotebookCacheList) IsOutdated

func (n *NotebookCacheList) IsOutdated() bool

IsOutdated returns true if the list has expired.

type NotestoreClient

type NotestoreClient interface {
	// FindNotes searches for the notes based on the filter.
	FindNotes(filter *NoteFilter, offset, count int) ([]*Note, error)
	// GetAllNotebooks returns all the of users notebooks.
	GetAllNotebooks() ([]*Notebook, error)
	// GetNotebook
	GetNotebook(guid string) (*Notebook, error)
	// CreateNotebook
	CreateNotebook(b *Notebook, defaultNotebook bool) error
	// GetNoteContent gets the note's content from the notestore.
	GetNoteContent(guid string) (string, error)
	// UpdateNote update's the note.
	UpdateNote(note *Note) error
	// DeleteNote removes a note from the user's notebook.
	DeleteNote(guid string) error
	// CreateNote creates a new note on the server.
	CreateNote(note *Note) error
	// UpdateNotebook updates the notebook on the server.
	UpdateNotebook(book *Notebook) error
}

NotestoreClient is the interface for the notestore.

type Settings

type Settings struct {
	// APIKey is the user's session key.
	APIKey string
	// Credential holds the user's credential data.
	Credential *Credential
}

Settings is a struct holding the user's settings for the application.

type Storager

type Storager interface {
	io.Closer
	GetSettings() (*Settings, error)
	StoreSettings(*Settings) error
	// GetNotebookCache returns the stored NotebookCacheList.
	GetNotebookCache() (*NotebookCacheList, error)
	// StoreNotebookList saves the list to the database.
	StoreNotebookList(list *NotebookCacheList) error
	// SaveSearch stores a note search to the database.
	SaveSearch([]*Note) error
	// GetSearch returns a saved note search from the database.
	GetSearch() ([]*Note, error)
	// SaveNoteRecoveryPoint saves the note as a recovery point.
	SaveNoteRecoveryPoint(*Note) error
	// GetNoteREcoveryPoint returns the saved note.
	GetNoteRecoveryPoint() (*Note, error)
}

Storager is the interface for backend storage.

type UserCredentialStore added in v0.5.0

type UserCredentialStore interface {
	// Add saves a new credential to the store.
	Add(*Credential) error
	// Remove deletes a credential from the store.
	Remove(*Credential) error
	// GetAll returns all credentials in the store.
	GetAll() ([]*Credential, error)
	// GetByIndex returns a user credential by its index.
	GetByIndex(index int) (*Credential, error)
}

UserCredentialStore provides an interface to a backend that stores a user's credentials.

type VimEditor added in v0.5.0

type VimEditor struct{}

VimEditor opens the note in VIM and lets the user edit the note.

func (*VimEditor) Edit added in v0.5.0

func (e *VimEditor) Edit(file CacheFile) error

Edit opens the CacheFile with VIM.

Directories

Path Synopsis
api
Package api provides interface for the Evernote API.
Package api provides interface for the Evernote API.

Jump to

Keyboard shortcuts

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