setup

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package setup implements the interactive `initialize` subcommand: language, API credentials, Telegram login and optional system service registration.

Index

Constants

This section is empty.

Variables

View Source
var ErrAborted = errors.New("aborted")

ErrAborted is returned when stdin closes mid-prompt.

Functions

func Initialize

func Initialize(ctx context.Context, opt Options) error

Initialize runs the interactive setup in the data home.

func Login

func Login(ctx context.Context, u *UI, client *telegram.Client, askPhone func() (string, error)) (*tg.User, error)

Login drives the code + 2FA flow on an already running client. askPhone is called first and again whenever Telegram rejects the number.

Types

type ClientFactory

type ClientFactory func(cfg *config.Config) *telegram.Client

ClientFactory builds the Telegram client for a config. main passes the app's constructor so login uses the same device info and session file.

type Options

type Options struct {
	Home      string // data home, already resolved
	Command   string // registered shell command name
	NewClient ClientFactory
	// NewBotClient builds the companion bot client for a config.
	NewBotClient ClientFactory
}

Options configures Initialize.

type Service

type Service struct {
	Name    string // unit name without .service
	Binary  string // absolute path of the papervalet binary
	Home    string // PAPERVALET_HOME
	Command string // PAPERVALET_CMD, for hints printed by the bot
	User    bool   // user unit (~/.config/systemd/user) instead of system unit
}

Service describes a systemd unit running one PaperValet instance.

func (Service) Exists

func (s Service) Exists() bool

Exists reports whether the unit file is already present.

func (Service) Install

func (s Service) Install() error

Install writes the unit, reloads systemd, enables and (re)starts it.

func (Service) LogsCmd

func (s Service) LogsCmd() string

LogsCmd and StatusCmd are the commands users run to inspect the service.

func (Service) StatusCmd

func (s Service) StatusCmd() string

func (Service) Unit

func (s Service) Unit() string

Unit renders the unit file.

type UI

type UI struct {
	Lang i18n.Lang
	// contains filtered or unexported fields
}

UI is a small line-oriented terminal prompter. All text goes through the setup catalog in the language picked at the start.

func NewUI

func NewUI() *UI

NewUI builds a prompter on stdin/stdout.

func (*UI) Ask

func (u *UI) Ask(label, def string, valid func(string) bool, invalidKey string) (string, error)

Ask reads a line; empty input returns def. valid may be nil.

func (*UI) AskMasked

func (u *UI) AskMasked(label, def string, valid func(string) bool, invalidKey string) (string, error)

AskMasked is Ask but shows a masked form of def in the prompt.

func (*UI) Blank

func (u *UI) Blank()

Blank prints an empty line.

func (*UI) Choose

func (u *UI) Choose(options []string, def int, invalid string) (int, error)

Choose shows a numbered list and returns the picked index. invalid is shown on bad input; it is passed in because the language may not be chosen yet.

func (*UI) Cmd

func (u *UI) Cmd(s string) string

Cmd highlights a shell command inside a sentence.

func (*UI) Confirm

func (u *UI) Confirm(label string, def bool) (bool, error)

Confirm asks a yes/no question.

func (*UI) Err

func (u *UI) Err(s string)

Err prints an error line.

func (*UI) Hint

func (u *UI) Hint(s string)

Hint prints dimmed helper text.

func (*UI) OK

func (u *UI) OK(s string)

OK prints a success line.

func (*UI) Secret

func (u *UI) Secret(label string) (string, error)

Secret reads a line without echo when stdin is a terminal.

func (*UI) Step

func (u *UI) Step(n, total int, key string)

Step prints a numbered section header.

func (*UI) T

func (u *UI) T(key string, args ...any) string

T translates a setup key into the chosen language.

func (*UI) Title

func (u *UI) Title(s string)

Title prints the banner.

func (*UI) Warn

func (u *UI) Warn(s string)

Warn prints a warning line.

Jump to

Keyboard shortcuts

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