@0xengine/meow 1.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of @0xengine/meow might be problematic. Click here for more details.

package/build/index.js ADDED
@@ -0,0 +1,95 @@
1
+ import process from 'node:process';
2
+ import { y as yargsParser, t as trimNewlines, r as redent, c as camelcaseKeys } from './dependencies.js';
3
+ import { buildOptions } from './options.js';
4
+ import { buildParserOptions } from './parser.js';
5
+ import { checkUnknownFlags, validate, checkMissingRequiredFlags } from './validate.js';
6
+
7
+ const buildResult = ({pkg: packageJson, ...options}, parserOptions) => {
8
+ const argv = yargsParser(options.argv, parserOptions);
9
+ let help = '';
10
+
11
+ if (options.help) {
12
+ help = trimNewlines((options.help || '').replace(/\t+\n*$/, ''));
13
+
14
+ if (help.includes('\n')) {
15
+ help = redent(help, options.helpIndent);
16
+ }
17
+
18
+ help = `\n${help}`;
19
+ }
20
+
21
+ if (options.description !== false) {
22
+ let {description} = options;
23
+
24
+ if (description) {
25
+ description = help ? redent(`\n${description}\n`, options.helpIndent) : `\n${description}`;
26
+ help = `${description}${help}`;
27
+ }
28
+ }
29
+
30
+ help += '\n';
31
+
32
+ const showHelp = code => {
33
+ console.log(help);
34
+ process.exit(typeof code === 'number' ? code : 2); // Default to code 2 for incorrect usage (#47)
35
+ };
36
+
37
+ const showVersion = () => {
38
+ console.log(options.version);
39
+ process.exit(0);
40
+ };
41
+
42
+ if (argv._.length === 0 && options.argv.length === 1) {
43
+ if (argv.version === true && options.autoVersion) {
44
+ showVersion();
45
+ } else if (argv.help === true && options.autoHelp) {
46
+ showHelp(0);
47
+ }
48
+ }
49
+
50
+ const input = argv._;
51
+ delete argv._;
52
+
53
+ if (!options.allowUnknownFlags) {
54
+ checkUnknownFlags(input);
55
+ }
56
+
57
+ const flags = camelcaseKeys(argv, {exclude: ['--', /^\w$/]});
58
+ const unnormalizedFlags = {...flags};
59
+
60
+ validate(flags, options);
61
+
62
+ for (const flagValue of Object.values(options.flags)) {
63
+ if (Array.isArray(flagValue.aliases)) {
64
+ for (const alias of flagValue.aliases) {
65
+ delete flags[alias];
66
+ }
67
+ }
68
+
69
+ delete flags[flagValue.shortFlag];
70
+ }
71
+
72
+ checkMissingRequiredFlags(options.flags, flags, input);
73
+
74
+ return {
75
+ input,
76
+ flags,
77
+ unnormalizedFlags,
78
+ pkg: packageJson,
79
+ help,
80
+ showHelp,
81
+ showVersion,
82
+ };
83
+ };
84
+
85
+ const meow = (helpText, options = {}) => {
86
+ const parsedOptions = buildOptions(helpText, options);
87
+ const parserOptions = buildParserOptions(parsedOptions);
88
+ const result = buildResult(parsedOptions, parserOptions);
89
+
90
+ process.title = result.pkg.bin ? Object.keys(result.pkg.bin).at(0) : result.pkg.name;
91
+
92
+ return result;
93
+ };
94
+
95
+ export { meow as default };