At the moment, the call stack for librarian is:
main --> librarian.Run --> command.RunCommand --> maybeGetLanguageRepo + maybeLoadStateAndConfig + execute
This creates a level of abstraction that requires all commands to follow the abstraction of maybeGetLanguageRepo + maybeLoadStateAndConfig + execute, which isn't always applicable (at the moment, it only applies to 5 out of the 7 existing commands).
To eliminate the command.RunCommand abstraction, change the current Command struct:
type Command struct {
// Name is the unique identifier for the command.
Name string
// Short is a concise description shown in the 'librarian -h' output.
Short string
// maybeGetLanguageRepo attempts to obtain a language-specific Git
// repository, cloning if necessary. Returns nil if not applicable.
maybeGetLanguageRepo func(workRoot string) (*gitrepo.Repo, error)
// maybeLoadStateAndConfig attempts to load pipeline state and config, even if no
// language repo is present.
maybeLoadStateAndConfig func(languageRepo *gitrepo.Repo) (*statepb.PipelineState, *statepb.PipelineConfig, error)
// execute runs the command's with the provided context.
execute func(*commandState) error
// flagFunctions are functions to initialize the command's flag set.
flagFunctions []func(fs *flag.FlagSet)
// flags is the command's flag set for parsing arguments and generating
// usage messages. This is populated for each command in init().
flags *flag.FlagSet
}
To:
type Command struct {
// Name is the unique identifier for the command.
Name string
// Short is a concise description shown in the 'librarian -h' output.
Short string
// Run executes the command.
Run func(ctx context.Context) error
// flagFunctions are functions to initialize the command's flag set.
flagFunctions []func(fs *flag.FlagSet)
// flags is the command's flag set for parsing arguments and generating
// usage messages. This is populated for each command in init().
flags *flag.FlagSet
}
At the moment, the call stack for librarian is:
main --> librarian.Run --> command.RunCommand --> maybeGetLanguageRepo + maybeLoadStateAndConfig + execute
This creates a level of abstraction that requires all commands to follow the abstraction of maybeGetLanguageRepo + maybeLoadStateAndConfig + execute, which isn't always applicable (at the moment, it only applies to 5 out of the 7 existing commands).
To eliminate the
command.RunCommandabstraction, change the current Command struct:To: