MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / NewCLI

Function NewCLI

cmd/main.go:103–126  ·  view source on GitHub ↗

NewCLI creates the command-line interface (CLI) for the LedgerForge application. It sets up the root command and subcommands like serverCommands, workerCommands, and migrateCommands.

()

Source from the content-addressed store, hash-verified

101// NewCLI creates the command-line interface (CLI) for the LedgerForge application.
102// It sets up the root command and subcommands like serverCommands, workerCommands, and migrateCommands.
103func NewCLI() *LedgerForge {
104 var configFile string // Configuration file path (defaults to ./ledgerforge.json)
105 b := &ledgerforgeInstance{} // Instance of LedgerForge to be passed into commands
106
107 // Define the root command with usage and description.
108 rootCmd := &cobra.Command{
109 Use: "ledgerforge",
110 Short: "Open source ledger", // Brief description for the CLI tool
111 Run: func(cmd *cobra.Command, args []string) {}, // Main function for the root command
112 }
113
114 // Add a persistent flag to the root command for specifying the config file.
115 rootCmd.PersistentFlags().StringVar(&configFile, "config", "./ledgerforge.json", "Configuration file for LedgerForge")
116
117 // Set the persistent pre-run hook to initialize the app and config before executing any command.
118 rootCmd.PersistentPreRunE = preRun(b, &configFile)
119
120 // Add various subcommands to the root command.
121 rootCmd.AddCommand(serverCommands(b)) // Command for starting the server
122 rootCmd.AddCommand(workerCommands(b)) // Command for worker processes
123 rootCmd.AddCommand(migrateCommands(b)) // Command for database/schema migrations
124
125 return &LedgerForge{cmd: rootCmd}
126}
127
128// executeCLI runs the root command, handling any errors that occur during execution.
129// It serves as the main entry point for the CLI application.

Callers 1

mainFunction · 0.85

Calls 4

preRunFunction · 0.85
serverCommandsFunction · 0.85
workerCommandsFunction · 0.85
migrateCommandsFunction · 0.85

Tested by

no test coverage detected