cli

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package cli holds what the subcommands do, once internal/app has parsed their arguments.

Package cli holds what the subcommands do, once internal/app has parsed their arguments. What a command is asked for goes to stdout; what it has to say about how that went goes to stderr.

Index

Constants

This section is empty.

Variables

View Source
var ErrCanceled = errors.New("canceled")

ErrCanceled says the user said no. The exit code is 130 and nothing more is printed.

View Source
var ErrFileWithFlags = errors.New("a file name goes with piped content, not with -d, --add, --remove or --rename")

ErrFileWithFlags says a file to replace was named along with flags, which take no content.

View Source
var ErrNothingToCreate = errors.New("give files to create the gist from, or pipe the content")

ErrNothingToCreate says gist new was given nothing to read.

Functions

func Auth

func Auth(ctx context.Context, stdout, stderr io.Writer, source string, c AccessChecker) int

Auth prints where the token came from and what it can do, and returns the exit code: 1 when it cannot be used for gists.

Types

type AccessChecker

type AccessChecker interface {
	CheckAccess(ctx context.Context) (github.Access, error)
}

AccessChecker says what the token can do.

type CLI

type CLI struct {
	Stdin          io.Reader
	Stdout, Stderr io.Writer
	// StdinTTY and StdoutTTY say they are terminals.
	StdinTTY, StdoutTTY bool

	API    *github.Client
	Editor *edit.Editor
	Log    *slog.Logger
	// Open opens a URL in the browser.
	Open func(url string) error
	// Run runs a program on the user's terminal.
	Run func(name string, args ...string) error
	// EditorCommand is the editor set in the config.
	EditorCommand string
	// CacheDir is where lists and contents are kept.
	CacheDir string
	// Now is the time.
	Now func() time.Time
	// contains filtered or unexported fields
}

CLI is what the commands run with.

func (*CLI) Clone

func (c *CLI) Clone(ctx context.Context, arg, dir string) error

Clone clones a gist with git, the way to work on images and many files, which the API cannot carry.

func (*CLI) Delete

func (c *CLI) Delete(ctx context.Context, args []string, yes bool) error

Delete removes gists, asking first on a terminal. Nothing is removed unless every one of them can be found.

func (*CLI) Edit

func (c *CLI) Edit(ctx context.Context, arg, file string, o EditOptions) error

Edit changes a gist without an editor.

func (*CLI) List

func (c *CLI) List(ctx context.Context, o ListOptions) error

List prints the list of gists.

func (*CLI) New

func (c *CLI) New(ctx context.Context, paths []string, o NewOptions) error

New creates a gist from files, or from stdin, and prints its URL.

func (*CLI) NewInForm

func (c *CLI) NewInForm(ctx context.Context, o NewOptions, form func() (*model.Gist, error)) error

NewInForm runs the form, and says what the form made as New would.

func (*CLI) OpenGist

func (c *CLI) OpenGist(ctx context.Context, arg string) error

OpenGist opens a gist in the browser, or the user's gists when arg is "".

func (*CLI) Resolve

func (c *CLI) Resolve(ctx context.Context, arg string) (string, error)

Resolve turns what the user wrote into a gist's ID. What is not found in the kept list is looked for in a fresh one, as it may have been made elsewhere.

func (*CLI) View

func (c *CLI) View(ctx context.Context, arg, file string, o ViewOptions) error

View prints a gist's files as written. The content in GitHub's JSON is rewritten by the API client and cut at 1 MB, so it is read from raw_url.

type EditOptions

type EditOptions struct {
	Description *string
	Add         []string
	Remove      []string
	Rename      []string
	// Base and BaseDescription say what the change must be based on.
	Base            string
	BaseDescription *string
	// Yes sends what was edited without asking, and Force goes over what
	// changed on GitHub.
	Yes, Force bool
}

EditOptions are the flags of gist edit.

type ListOptions

type ListOptions struct {
	Public, Secret, Starred, Refresh, JSON bool
	Limit                                  int
}

ListOptions are the flags of gist list.

type NewOptions

type NewOptions struct {
	Description string
	Public      bool
	Filename    string
	Open, Copy  bool
	JSON        bool
}

NewOptions are the flags of gist new.

type ViewOptions

type ViewOptions struct {
	Files, JSON, Web bool
}

ViewOptions are the flags of gist view.

Jump to

Keyboard shortcuts

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