m5cli

package module
v0.0.0-...-9e8c0e8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 27, 2024 License: AGPL-3.0 Imports: 29 Imported by: 0

README

m5cli

m5cli is the CLI element of the m5 Go application. Aimed at LwDITA and beyond.

License

Note that this is GNU Affero -licensed, not MIT-licensed like most of the libraries it uses. This means that use over a network is distribution, requiring disclosure of modifications to source code.

Documentation

Overview

Package m5cli 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

Constants

This section is empty.

Variables

View Source
var AllGLinks mcfile.GLinks

AllGLinks gathers all GLinks in the current run's input set.

View Source
var LOG_LEVEL_EXEC_STAGES = LU.LevelDebug
View Source
var LOG_LEVEL_FILE_INTRO = LU.LevelInfo // 6
View Source
var LOG_LEVEL_FILE_READING = LU.LevelOkay // 5
View Source
var LOG_LEVEL_REF_LINKING = LU.LevelInfo // 6
View Source
var LOG_LEVEL_WEB = LU.LevelDebug

Functions

func CLI

func CLI(args []string) error

CLI parses the arguments passed in (tipicly os.Args) and then processes them; therefore it is very easy to pass in whatever arguments are suitable for testing.

NOTE: os.Args is writable so you can also assign your own set of argument - this might 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 (and perhaps what to return to the shell via os.Exit).

NOTE: Do not use logging in the code until the point where the command line invocation has been sorted out.

Outline of operation (possibly OBS):

  1. flargs (command line "flag arguments") are defined in a func init(), so that they are available for a no-CLI-arg help message
  2. Check for no-CLI-arg invocation that gets a help message and exits
  3. InitLogging
  4. Samples() can do library demos and other very meta stuff
  5. NewXmlAppCfg creates XmlAppCfg config from CLI arguments
  6. NewXmlAppEnv creates XmlAppEnv env'mt from XmlAppCfg
  7. XmlAppEnv.Exec() to Get Things Done
  8. If REST port nr given, run web UI

.

func DoSamples

func DoSamples()

DoSamples does demo type stuff and can be skipped; it does use (and demo) mlog's L.L

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 RunRest

func RunRest(portNr int) error

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

func RunWeb(portNr int) error

Notes:

  • Does not launch a goroutine.
  • Call with env.WebPort .
  • Used Gorilla mux, but now use pilot version of new Go ServeMux.

Dedicated servers:

Main server (with h2c):

  • /all :: list of all endpoints
  • / :: something bland
  • /app :: the wasm SPA
  • /static :: static content
  • /about
  • /contact
  • /health (or?)

- /db .

func StcRootHdlr

func StcRootHdlr(w http.ResponseWriter, r *http.Request)

func TopicRootHdlr

func TopicRootHdlr(w http.ResponseWriter, r *http.Request)

Types

type AllFlargs

type AllFlargs struct {
	// contains filtered or unexported fields
}

func (AllFlargs) String

func (a AllFlargs) String() string

type ContentityProcessor

type ContentityProcessor func(
	p *mcfile.Contentity, e error) (*mcfile.Contentity, error)

ContentityProcessor (see 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.

Note that to declare a func that is a ContentityProcessor, the func's signature is the RH side of this, NOT the LH side: don't try to declare a "ContentityProcessor" named as such. .

type XmlAppCfg

type XmlAppCfg struct {
	AppName     string
	CmdTail     []string
	XmllintPath string
	AllFlargs
}

XmlAppCfg can probably be used with various 3rd-party utilities.

type XmlAppEnv

type XmlAppEnv struct {
	DR.SimpleRepo
	Infiles       []FU.FSItem
	Indirs        []FU.FSItem
	IndirFSs      []mcfile.ContentityFS // was: []ExpanDir
	Outdir, Dbdir FU.FSItem             // NOT ptr! Barfs at startup.
	Xmlcatfile    FU.FSItem             // NOT ptr! Barfs at startup.
	Xmlschemasdir FU.FSItem             // 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) Exec

func (env *XmlAppEnv) Exec() error

Exec does all execution of all stages for every mcfile.Contentity, altho only after all prep has already been done by other funcs. The key input is an *XmlAppEnv. .

Directories

Path Synopsis
Package exec is home to functions called from m5's cli/Exec(), which is where all the "real work" gets done.
Package exec is home to functions called from m5's cli/Exec(), which is where all the "real work" gets done.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL