prefs

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package prefs remembers what you ran last time.

Filling in the same interface, destination and MAC on every invocation gets old fast, so Wireblast writes each run's settings to ~/.wireblast and offers them back as the starting point for the next interactive session.

Two rules keep this from becoming surprising:

  • Anything you pass on the command line wins over what was saved.
  • --no-tui ignores saved settings entirely. A script has to mean exactly what it says, whatever happens to be in a file in someone's home directory.

Index

Constants

View Source
const (
	// DirName is the directory under the user's home.
	DirName = ".wireblast"
	// LastFile holds the most recent run, used to prepopulate the wizard.
	LastFile = "last-run.json"
	// HistoryFile holds recent runs, newest first.
	HistoryFile = "history.json"
	// HistoryLimit is how many runs are kept.
	HistoryLimit = 20
)

Layout of the state directory.

Variables

This section is empty.

Functions

func Merge

func Merge(flags config.Config, saved config.Config, changed func(flag string) bool) config.Config

Merge produces the configuration an interactive session should start from: the remembered run, with anything given on the command line laid over the top.

changed reports whether a flag was actually passed, so a value that merely happens to equal its default does not count as a choice.

Types

type Entry

type Entry struct {
	// At is when the run started.
	At time.Time `json:"at"`
	// Config is what it was configured with.
	Config config.Config `json:"config"`
}

Entry is one remembered run.

func (Entry) Summary

func (e Entry) Summary() string

Summary renders an entry as one line, for a "recent runs" list.

type Store

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

Store reads and writes the remembered settings.

Every method degrades quietly: an unreadable or corrupt state file must never stop someone generating traffic, so failures mean "no history" rather than an error the user has to deal with.

func New

func New() *Store

New returns a Store rooted at ~/.wireblast, or at $WIREBLAST_HOME when that is set (which is also how the tests get a scratch directory).

func NewAt

func NewAt(dir string) *Store

NewAt returns a Store rooted at an explicit directory.

func (*Store) Dir

func (s *Store) Dir() string

Dir is where the state lives, or "" when there is nowhere to keep it.

func (*Store) Forget

func (s *Store) Forget() error

Forget removes everything Wireblast has remembered.

func (*Store) History

func (s *Store) History() []Entry

History returns the remembered runs, newest first.

func (*Store) Last

func (s *Store) Last() (config.Config, bool)

Last returns the most recent run's configuration, and whether there was one.

func (*Store) Save

func (s *Store) Save(cfg *config.Config) error

Save records a run as the most recent one and adds it to the history.

It returns an error so a caller can log it if it wants to, but nothing in Wireblast treats a failure here as fatal.

Jump to

Keyboard shortcuts

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