m5cli

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

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

Go to latest
Published: Nov 6, 2025 License: AGPL-3.0 Imports: 31 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 mcfile.GLinks in the current run's input set. This should actually be re-entrant, like mcfile.ContentityEngine.

View Source
var InputExts = []string{
	".dita", ".map", ".ditamap", ".xml",
	".md", ".markdown", ".mdown", ".mkdn",
	".html", ".htm", ".xhtml",
	".png", ".gif", ".jpg", ".svg"}

InputExts is a whitelist that more than covers the file types associated with the LwDITA spec. Of course, check for them case-insensitively.

View Source
var LOG_LEVEL_EXEC_STAGES = LU.LevelInfo // 6
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.LevelDebug // 7
View Source
var LOG_LEVEL_WEB = LU.LevelDebug // 7

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 InitContentityDebugFiles

func InitContentityDebugFiles(InfileContentities []*mcfile.Contentity, doTotalTextal bool)

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 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 WriteContentityFStreeFiles

func WriteContentityFStreeFiles(IndirContentityFSs []mcfile.ContentityFS)

Types

type AllFlargs

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

func (AllFlargs) String

func (a AllFlargs) String() string

type InputPathItems

type InputPathItems struct {
	NamedPaths []string              // copied from input arg
	NamedFiles []FU.FSItem           // was: env.Infiles
	NamedDirrs []FU.FSItem           // was: env.Indirs
	NamedMiscs []FU.FSItem           // new
	DirCntyFSs []mcfile.ContentityFS // was: env.InDirFSs
	AllCntys   []*mcfile.Contentity
}

InputPathItems is for gathering, expanding (directories), verifying, and loading files and directories specified on the command line, and then organising everything as one large array of mcfile.Contentity.

  • [NamedPaths] is an input slice of paths of files and directories; a path to a file that ends with "/" (or os.Sep) throws a panic
  • [NamedFiles] is a slice of [fileutils.FSItem] for files named e.g. on the CLI
  • [NamedDirs] is a slice of [fileutils.FSItem] for dirs named e.g. on the CLI
  • [DirCntyFSs] is a slice of mcfile.ContentityFS, one per element of [NamedDirs]
  • [AllCntys] is an output slice of mcfile.Contentity that collects all Contentities (a) named by [NamedFiles], and (b) gathered by expanding [NamedDirs] and then walking their [DirCntyFSs]
  • Everything should implement interface [Errer]

FIXME: Add NamedSymls .

func DoInpaths

func DoInpaths(inPaths []string) *InputPathItems

DoInpaths processes a list of paths of any type - files, directories, symlinks, "other". Its processing is pretty straightforward:

  • Use input []string to generate []FSItem
  • Use FSItem.IsDir (and other funcs) to append each FSItem to the correct slice: files/dirrs/miscs
  • Check for errors along the way, and use the Errer embedded in each FSItem
  • Resolve symlinks, appending them to files or dirrs, but keep them sandboxed by using os.Root

.

type XmlAppCfg

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

XmlAppCfg can probably be used in other scenarios, and with various 3rd-party utilities.

type XmlAppEnv

type XmlAppEnv struct {
	DRP.SimpleRepo
	InputPathItems
	//	Infiles       []FU.FSItem // bye
	//	Indirs        []FU.FSItem // bye
	//	IndirFSs      []mcfile.ContentityFS // bye
	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.
	// IsSingleFile is a convenience flag, and a
	// 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
}

XmlAppEnv should be usable in other apps & scenarios too.

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. .

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