pub struct ArgConfig {
pub uuid: Uuid,
pub uuid_gen: bool,
pub db_url: String,
pub table: String,
pub cfg: HashMap<String, String>,
pub token: Token,
pub pk: Option<KeyFile>,
pub secret: Option<String>,
pub verbose: Opt,
pub quiet: Opt,
pub help: Opt,
}Expand description
App startup args:
-
db connection url: usually the first arg
- or prefix with: ’–db ’ (optional, default postgres:// , trying to identify by prefix)
-
config table name in format: schema.table, usually the second arg trying to identify with a dot in the middle.
- or prefix with: ’–config ’ (optional, default public.{the_appname})
-
UUID this app instance to use as a node id or config recognition. trying to auto identify a UUID formatted string.
- or prefix with ’–uuid ’
-
token (db pwd) script name usually the third arg (required feature ‘token’)
- or prefix with ’–token ’
-
token live in minutes, usually the forth arg (required feature ‘token’)
- or prefix with ’–ttl ’
-
(Private) Key text file name to use with RSA OR AES encryption (required feature ‘rsa’)
- or prefix with ’–key ’
-
cipher secret for AES taken from env [SECRET] (more secure) OR cml –secret (not recommended)
Also: compile with keep_env_secret feature to not remove from env
Alternative configuration:
- file name, usually the first arg
- or prefix with ’–file ’
File format:
- db: OR db=
- config: OR config=
- uuid: OR uuid=
- token: OR token=
- ttl: OR ttl=
- pk: OR pk=
params passed in cmd line override params loaded from file & env.
env:
- PGPASSWORD, in case of postgres db url, use to connect to the DB
- PASSPHRASE, in case of RSA private key required a passphrase
- SECRET
Fields§
§uuid: Uuidinstance ID
uuid_gen: boolindicate the instance uuid was set or autogenerated on (every) start
db_url: Stringdatabase connection string
table: StringFormat: schema.table
cfg: HashMap<String, String>key=value loaded from file if present
token: Tokentoken (i.e. db pwd) script name usually the third arg (required feature ‘token’)
pk: Option<KeyFile>RSA private key file name to use with RSA OR AES encryption (required feature ‘rsa’)
secret: Option<String>cipher secret for AES taken from env [SECRET] OR cml –secret use keep_env_secret feature to not remove from env
verbose: Opt-v / –verbose / –debug
quiet: Opt-q / –quiet / –batch
help: Opt-h / –help / –info
Implementations§
Source§impl ArgConfig
impl ArgConfig
Sourcepub fn from_args() -> Result<ArgConfig, String>
pub fn from_args() -> Result<ArgConfig, String>
backward compatibility but not correct info! Use: ArgConfig::from_args2(env!(“CARGO_PKG_NAME”), env!(“CARGO_PKG_VERSION”))
Sourcepub fn from_args2(
app_name: &str,
app_version: &str,
) -> Result<ArgConfig, String>
pub fn from_args2( app_name: &str, app_version: &str, ) -> Result<ArgConfig, String>
app_name / app_version should be the caller’s crate identity, e.g.
ArgConfig::from_args(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION")).
They can’t default to marg’s own env!() here since that macro resolves
at compile time against whichever crate the source lives in (marg itself),
not against whatever binary ends up calling this function.