docutils-ts
Version:
Port of the Python Docutils library to TypeScript
102 lines (99 loc) • 4.1 kB
TypeScript
import { ArgumentParser, ArgumentOptions, Namespace } from 'argparse';
import SettingsSpec from './settingsSpec.js';
import { SettingsSpecType, ConfigSettings, LoggerType } from './types.js';
import { Settings } from './index.js';
export declare function validateBoolean(parser: ArgumentParser, namespace: Namespace, values: any[], optionString: (string | null)): boolean;
interface Thresholds {
info: number;
warning: number;
error: number;
severe: number;
none: number;
}
/**
Check/normalize three-value settings:
True: '1', 'on', 'yes', 'true'
False: '0', 'off', 'no','false', ''
any other value: returned as-is.
*/
export declare function validateTernary(parser: ArgumentParser, namespace: Namespace, values: any[], optionString: (string | null)): boolean | any;
/**
Interpret filesystem path settings relative to the `base_path` given.
Paths are values in `pathdict` whose keys are in `keys`. Get `keys` from
`OptionParser.relative_path_settings`.
*/
/** Parser for command-line and library use. The `settings_spec`
specification here and in other Docutils components are merged to build
the set of command-line options and runtime settings for this process.
Common settings (defined below) and component-specific settings must not
conflict. Short options are reserved for common settings, and components
are restrict to using long options.
*/
export interface OptionParserArgs {
description?: string;
usage?: string;
readConfigFiles?: boolean;
components?: (SettingsSpec | undefined)[];
settingsSpecs?: SettingsSpecType[];
defaults?: ConfigSettings;
logger: LoggerType;
}
export declare class OptionParser extends ArgumentParser {
settingsSpec: SettingsSpecType[];
configSectionDependencies: string[];
version?: string;
configFiles: string[];
lists: {};
defaults: ConfigSettings;
/** Docutils configuration files, using ConfigParser syntax. Filenames
* will be tilde-expanded later. Later files override earlier ones.
*/
standardConfigFiles: string[];
/** Possible inputs for for --report and --halt threshold values. */
thresholdChoices: string[];
/**Lookup table for --report and --halt threshold values.*/
thresholds: Thresholds;
defaultErrorEncoding: string;
defaultErrorEncodingErrorHandler: string;
/**
Defaults for settings that don't have command-line option equivalents. */
settingsDefaults: {
[propName: string]: any;
};
relativePathSettings: string[];
configSection: string;
components: (SettingsSpec | undefined)[];
/** Default version message. */
versionTemplate: string;
private logger;
constructor(args: OptionParserArgs);
/**
* For each component, first populate from the `SettingsSpec.settings_spec`
* structure, then from the `SettingsSpec.settingsDefaults` dictionary.
* After all components have been processed, check for and populate from
* each component's `SettingsSpec.settingsDefaultOverrides` dictionary.
*/
populateFromComponents(components: (SettingsSpec | undefined)[]): void;
/** Return list of config files, from environment or standard. */
getStandardConfigFiles(): string[];
getStandardConfigSettings(): ConfigSettings;
/** Returns a dictionary containing appropriate config file settings. */
getConfigFileSettings(configFile: string): {};
/** Store positional arguments as runtime settings. */
checkValues(values: ConfigSettings, args: string[]): ConfigSettings;
checkArgs(args: string[]): [string?, string?];
setDefaultsFromDict(defaults: ConfigSettings): void;
getDefaultValues(): Settings;
/**
* Get an option by its dest.
*
* If you're supplying a dest which is shared by several options,
* it is undefined which option of those is returned.
*
* A KeyError is raised if there is no option with the supplied
* dest.
**/
getOptionByDest(dest: string): ArgumentOptions;
toString(): string;
}
export {};