MCPcopy Create free account
hub / github.com/BYVoid/OpenCC / parseArgs

Function parseArgs

node/cli.js:87–138  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

85}
86
87function parseArgs(args) {
88 const options = {
89 config: 's2t.json',
90 input: null,
91 output: null,
92 resourceZip: null,
93 includeTofuRiskDictionaries: false,
94 help: false,
95 version: false,
96 };
97
98 for (let i = 0; i < args.length; i += 1) {
99 const arg = args[i];
100 if (arg === '-h' || arg === '--help') {
101 options.help = true;
102 } else if (arg === '-v' || arg === '--version') {
103 options.version = true;
104 } else if (arg === '-c' || arg === '--config') {
105 options.config = readOptionValue(args, i, arg);
106 i += 1;
107 } else if (arg.startsWith('--config=')) {
108 options.config = readInlineOptionValue(arg, '--config');
109 } else if (arg === '--resource-zip') {
110 options.resourceZip = readOptionValue(args, i, arg);
111 i += 1;
112 } else if (arg.startsWith('--resource-zip=')) {
113 options.resourceZip = readInlineOptionValue(arg, '--resource-zip');
114 } else if (arg === '-i' || arg === '--input') {
115 options.input = readOptionValue(args, i, arg);
116 i += 1;
117 } else if (arg.startsWith('--input=')) {
118 options.input = readInlineOptionValue(arg, '--input');
119 } else if (arg === '-o' || arg === '--output') {
120 options.output = readOptionValue(args, i, arg);
121 i += 1;
122 } else if (arg.startsWith('--output=')) {
123 options.output = readInlineOptionValue(arg, '--output');
124 } else if (arg === '--include-tofu-risk-dictionaries') {
125 options.includeTofuRiskDictionaries = true;
126 } else if (arg === '--inspect' || arg === '--segmentation') {
127 throw new Error(`${arg} is not supported by the npm CLI. Use the native OpenCC CLI instead.`);
128 } else if (arg === '--path' || arg.startsWith('--path=')) {
129 throw new Error('--path is not supported by the npm CLI. Pass an explicit config file path instead.');
130 } else if (arg === '--noflush' || arg === '--measured_result' || arg.startsWith('--measured_result=')) {
131 throw new Error(`${arg.split('=')[0]} is not supported by the npm CLI.`);
132 } else {
133 throw new Error(`Unknown option: ${arg}`);
134 }
135 }
136
137 return options;
138}
139
140function resolveConfigPath(config) {
141 if (BUILT_IN_CONFIG_NAMES.has(config) || OPTIONAL_JIEBA_CONFIGS.has(config) || path.isAbsolute(config)) {

Callers 1

mainFunction · 0.85

Calls 2

readOptionValueFunction · 0.85
readInlineOptionValueFunction · 0.85

Tested by

no test coverage detected