Documentation ¶
Overview ¶
Package mcm-cli provides a generic command line argument processing capability for XML-oriented programs. It provides a large set of useful arguments that can be individually (or as a group) enabled or disabled (i.e. hidden).
The package imports github.com/fbaube/(fileutils,stringutils,wasmutils) .
Index ¶
- Variables
- func CLI() error
- func DisableAllFlags()
- func DisableFlags(s string)
- func EnableAllFlags()
- func EnableFlags(s string)
- func EnvarNameFromFlagName(s string) string
- func FlagNameFromEnvarName(s string) string
- func HasFlag(haystack []string, needle string) bool
- func HomeHandler(w http.ResponseWriter, r *http.Request)
- func InitLogging(appName string)
- func MapRootHdlr(w http.ResponseWriter, r *http.Request)
- func ParseEnvars() error
- func PreParse()
- func RunRest(portNr int) error
- func RunWeb(portNr int) error
- func StcRootHdlr(w http.ResponseWriter, r *http.Request)
- func TopicRootHdlr(w http.ResponseWriter, r *http.Request)
- type AllFlargs
- type ContentityProcessor
- type ExpanDir
- type XmlAppCfg
- type XmlAppEnv
Constants ¶
This section is empty.
Variables ¶
var AllGLinks mcfile.GLinks
AllGLinks gathers all GLinks in the current run's input set.
var DB_FILENAME = "mmmc.db"
var LOG_LEVEL_EXEC_STAGES = LU.LevelDbg
var LOG_LEVEL_FILE_READING = LU.LevelDbg
var LOG_LEVEL_REF_LINKING = LU.LevelDbg
var LOG_LEVEL_WEB = LU.LevelDbg
Functions ¶
func CLI ¶
func CLI() error
CLI parses the contents of os.Args and then processes them.
NOTE: You can assign your own set of mock arguments to os.Args - it is writeable! This can be useful for testing, or for WASM usage.
An error from this func is returned unmodified and unprocessed, and so it is up to the caller to sort out its severity and how to handle it.
NOTE: Do not use logging in the code until the point where the command line invocation has been sorted out.
Outline of operation:
- flargs (command line flag arguments) are defined in a func init(), so that they are available for a no-CLI-arg help message
- Check for no-CLI-arg invocation that gets a help message and exits
- InitLogging
- PreParse() does preliminaries like library demos
- NewXmlAppCfg creates XmlAppCfg config from CLI arguments
- NewXmlAppEnv creates XmlAppEnv env'mt from XmlAppCfg
- XmlAppEnv.Exec() to Get Things Done
- If REST port nr given, run web UI
.
func EnvarNameFromFlagName ¶
func FlagNameFromEnvarName ¶
func HomeHandler ¶
func HomeHandler(w http.ResponseWriter, r *http.Request)
func InitLogging ¶
func InitLogging(appName string)
InitLogging starts with Targets[] empty, then 1) adds a console logger (i.e. Stdout), 2) adds a file logger named "[appName].log", 3) opens them both, 4) outputs a few demo log records
func MapRootHdlr ¶
func MapRootHdlr(w http.ResponseWriter, r *http.Request)
func ParseEnvars ¶
func ParseEnvars() error
ParseEnvars is based on https://scene-si.org/2020/04/28/extending-pflag-with-environment-variables/
func PreParse ¶
func PreParse()
PreParse does demo type stuff and can be skipped; it does use (and demo) mlog's L.L
func RunRest ¶
Does not launch a goroutine. Call with env.RestPort . Uses Gorilla mux, mainly cos now it's in archive mode. Instructions for usage are found [here](https://github.com/gorilla/mux#examples) or in alternate format github.com/gorilla/mux or in alternate format mux or in alternate format "[muxdox]"
[muxdox]: https://github.com/gorilla/mux#examples .
func RunWeb ¶
Does not launch a goroutine. Call with env.WebPort . Uses Gorilla mux, mainly cos now it's in archive mode. Instructions for usage are found [here](https://github.com/gorilla/mux#examples) or in alternate format github.com/gorilla/mux or in alternate format mux or in alternate format "[muxdox]"
[muxdox]: https://github.com/gorilla/mux#examples .
func StcRootHdlr ¶
func StcRootHdlr(w http.ResponseWriter, r *http.Request)
func TopicRootHdlr ¶
func TopicRootHdlr(w http.ResponseWriter, r *http.Request)
Types ¶
type ContentityProcessor ¶
type ContentityProcessor func( p *mcfile.Contentity, e error) (*mcfile.Contentity, error)
ContentityProcessor (seee ContentityStage !!) is most probably the best way to go. It preserves order of processing of MCFile's (unlike iterating thru a map of them), and the func signature is most def in the Go style, and the style IS CHAINABLE.
type ExpanDir ¶
type ExpanDir struct {
DirCt, FileCt,
ItemCt int
CtFS *mcfile.ContentityFS
}
type XmlAppEnv ¶
type XmlAppEnv struct { repo.SimpleRepo Infiles []FU.PathProps Indirs []FU.PathProps Inexpandirs []ExpanDir Outdir, Dbdir FU.PathProps // NOT ptr! Barfs at startup. Xmlcatfile FU.PathProps // NOT ptr! Barfs at startup. Xmlschemasdir FU.PathProps // NOT ptr! Barfs at startup. // Result of processing CLI arg for input file(s) IsSingleFile bool // Result of processing CLI args -c & -s *XU.XmlCatalogFile PrittOutput io.Writer // contains filtered or unexported fields }
func (*XmlAppEnv) ProcessDatabaseArgs ¶
ProcessDatabaseArgs should be able to process either a new DB OR an existing DB. .