Skip to content

bobcatalyst/mainfx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mainfx

This package provides a bootstrap for starting applications using Uber's FX library. It allows registering modules as basic subcommands.

Installation

Import the package into your Go project:

import "path/to/mainfx"

Usage

Register Subcommands

To register a subcommand, use imports with side effects :

cmd/server/main.go

func init() {
    mainfx.RegisterSubcommand("server", "Start the server",
        fx.Provide(NewServer),
        fx.Invoke(StartServer),
    )
}

main.go

import _ "cmd/server"

Running the Program

Call the Main function in your main package:

func main() {
    mainfx.Main()
}

mainfx Module

Some extra types are provided by mainfx.

*slog.Logger

The default slog.Logger when Main is called or a debug logger if debugging is enabled.

*OsArgs

OsArgs provides access to command-line arguments:

type OsArgs struct {
    ProgramName string   // The executable name
    ProgramArgs []string // Arguments passed to the program
    Command     string   // The first argument (subcommand)
    CommandArgs []string // Remaining arguments for the subcommand
    AllArgs     []string // All arguments
}

Help Output

When no subcommand is provided or the -h or --help flag is used, the program prints a list of available subcommands:

Available subcommands:
    server: "Start the server"

Debug Logging

Enable debug logging by building the program with the -tags debug flag.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages