A library for creating quick and effective CLI applications that have the process management build inside it.
You can find the API documentation here.
v7 replaces go-floc with an in-repo orchestration that is built on the standard library, and logrus with log/slog. Migration from v6 is mechanical.
- Update the import path to
github.com/cenk1cenk2/plumber/v7. Jobis nowfunc(ctx context.Context) error. Drop thefloc.Contextandfloc.Controlparameters, return the error plainly and stop the flow through the cancellation of the context instead ofctrl.Fail.- Callbacks take a context:
TaskFn,TaskListFnandCommandFnarefunc(ctx context.Context, x *X) error. The builders, the predicates and the wrappers of them,TaskListJobFn,TaskPredicateFnandTaskJobWrapperFn, stay without a context. Run,RunWith,RunBefore,RunAfter,RunSubtasks,RunCommandJob,RunCommandJobAsJobSequenceandRunCommandJobAsJobParalleltake the context as their first argument. Run a flow withRunJobs(job)under the root context of the application, or withRunJobsWith(ctx, job)under a context of your own.GuardResume(job)no longer takes result masks and swallows every error of the job.GuardResume(TASK_CANCELLED, job)becomesGuardIgnoreCancel(job), which only swallows the errors that are caused by the cancellation.GuardAlways(job, grace...)runs the job even when the context is already cancelled and takes an optional grace duration.- The
TASK_*result masks andNewJobResultMaskare removed in favor oferrors.Isandcontext.Cause. The shutdown of the application isErrShutdown. CreateBasicJobbecomesCreateJob,CreateJobWithContextis obsolete since every job has a context, andJobThenandJobElseare removed in favor ofJobSequenceandJobIf.- The capture API,
CaptureandResult[T], is removed. Pass the values with closures that write in to the typed fields of your own structs, where the order ofJobSequenceand the join ofJobParallelare what make them readable after the flow. - The loggers are
*slog.Loggerinstead of*logrus.Loggerand*logrus.Entry, therefore they have no printf methods anymore. Port the call sites by wrapping the message withfmt.Sprintf,log.Infof("%s", name)becomeslog.Info(fmt.Sprintf("%s", name)), and log the level that slog does not know about withlog.Log(ctx, logger.LevelTrace, message). LogLevelis an enum of its own that is parsed withParseLogLeveland stays the level of the configuration boundary and ofCommand.SetLogLevel.WithFieldandWithFieldsbecomeWithwith the attributes of slog,SetFormatteris gone since the format of the output is the one of plumber itself, and the controls of the root logger areSetLoggerLevel,GetLoggerLevel,SetLoggerOutputandSetLoggerReportCalleron the application.AppChanneland the exportedLockof the terminator are removed. The root context of the application together withSendError,SendFatalandSendExitreplace them, andSetExitFuncoverrides how the process exits.CombineTaskListstakes anything that implementsTaskLister, andJobberis the interface for anything that produces aJob.DeprecationNoticeandSetDeprecationNoticesare removed. Warn about the deprecated flags and environment variables of your own application from itsBeforefunction instead.- The
MARKDOWN_DOCandMARKDOWN_EMBEDpseudo-commands are removed. Opt in to thedocscommand withCommands: []*cli.Command{plumber.DocsCommand(p)}and callgo run . docs markdownorgo run . docs embedfrom your Taskfile instead, where--outputoverrides the file ofSetDocumentationOptionsfor that run. - Both
docs markdownanddocs embedrender the very same template, where--stylepicks between thefulldocument that opens with the headline of the application and theflagsfragment that only carries the flags and the commands. The styles default to the ones that the subcommands used to have,fullfordocs markdownandflagsfordocs embed. - The generated tables have no
Requiredcolumn anymore, since a required flag is bold and carries a trailing*that a legend underneath the table explains. The documentation also renders the positional arguments, the categories of the commands, the default texts, the mutually exclusive groups and the usage line of every command, and it collapses a flag category that repeats identically across the commands behind a disclosure element.