Skip to content

Instantly share code, notes, and snippets.

@djthorpe
Last active December 30, 2018 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djthorpe/b83833baa5c74d594ecbd08770ab3e6d to your computer and use it in GitHub Desktop.
Save djthorpe/b83833baa5c74d594ecbd08770ab3e6d to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"os"
// Frameworks
gopi "github.com/djthorpe/gopi"
// Modules
_ "github.com/djthorpe/gopi/sys/logger"
)
func Main(app *gopi.AppInstance, done chan<- struct{}) error {
app.Logger.Info("Started main thread")
if name, exists := app.AppFlags.GetString("name"); exists {
fmt.Println("Hello,", name)
} else {
fmt.Println("Hello, World (use -name flag to specify name)")
}
if wait, _ := app.AppFlags.GetBool("wait"); wait {
fmt.Println("Press CTRL+C to exit")
app.WaitForSignal()
}
return nil
}
func main() {
// Create the configuration
config := gopi.NewAppConfig("sys/logger")
config.AppFlags.FlagString("name", "", "Your name")
config.AppFlags.FlagBool("wait",true, "Wait for CTRL+C interrupt to end")
// Run the command line tool
os.Exit(gopi.CommandLineTool(config, Main))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment