Skip to content

Running without arguments breaksΒ #178

@eduwass

Description

@eduwass

Just running caz will show an error.


~ via 🐍 v3.13.2 underwent 1s
❯ caz
/opt/homebrew/lib/node_modules/caz/dist/cli.js:9
))}outputVersion(){let{name:t}=this.cli,{versionNumber:n}=this.cli.globalCommand;n&&console.log(${t}/${n} ${P})}checkRequiredArgs(){let t=this.args.filter(n=>n.required).length;if(this.cli.args.length<t)throw new p(missing required args for command `${this.rawName}`)}checkUnknownOptions(){let{options:t,globalCommand:n}=this.cli;if(!this.config.allowUnknownOptions){for(let e of Object.keys(t))if(e!=="--"&&!this.hasOption(e)&&!n.hasOption(e))throw new p(Unknown option `${e.length>1?--${e}:-${e}}`)}}checkOptionValue(){let{options:t,globalCommand:n}=this.cli,e=[...n.options,...this.options];for(let i of e){let s=t[i.name.split(".")[0]];if(i.required){let r=e.some(c=>c.negated&&c.names.includes(i.name));if(s===!0||s===!1&&!r)throw new p(option `${i.rawName}` value is missing)}}}},O=class extends b{constructor(t){super("@@global@@","",{},t)}},g=Object.assign,$=class extends _events.EventEmitter{constructor(t=""){super(),this.name=t,this.commands=[],this.rawArgs=[],this.args=[],this.options={},this.globalCommand=new O(this),this.globalCommand.usage("<command> [options]")}usage(t){return this.globalCommand.usage(t),this}command(t,n,e){let i=new b(t,n||"",e,this);return i.globalCommand=this.globalCommand,this.commands.push(i),i}option(t,n,e){return this.globalCommand.option(t,n,e),this}help(t){return this.globalCommand.option("-h, --help","Display this message"),this.globalCommand.helpCallback=t,this.showHelpOnExit=!0,this}version(t,n="-v, --version"){return this.globalCommand.version(t,n),this.showVersionOnExit=!0,this}example(t){return this.globalCommand.example(t),this}outputHelp(){this.matchedCommand?this.matchedCommand.outputHelp():this.globalCommand.outputHelp()}outputVersion(){this.globalCommand.outputVersion()}setParsedInfo({args:t,options:n},e,i){return this.args=t,this.options=n,e&&(this.matchedCommand=e),i&&(this.matchedCommandName=i),this}unsetMatchedCommand(){this.matchedCommand=void 0,this.matchedCommandName=void 0}parse(t=L,{run:n=!0}={}){this.rawArgs=t,this.name||(this.name=t[1]?G(t[1]):"cli");let e=!0;for(let s of this.commands){let r=this.mri(t.slice(2),s),c=r.args[0];if(s.isMatched(c)){e=!1;let l=g(g({},r),{args:r.args.slice(1)});this.setParsedInfo(l,s,c),this.emit(command:${c},s)}}if(e){for(let s of this.commands)if(s.name===""){e=!1;let r=this.mri(t.slice(2),s);this.setParsedInfo(r,s),this.emit("command:!",s)}}if(e){let s=this.mri(t.slice(2));this.setParsedInfo(s)}this.options.help&&this.showHelpOnExit&&(this.outputHelp(),n=!1,this.unsetMatchedCommand()),this.options.version&&this.showVersionOnExit&&this.matchedCommandName==null&&(this.outputVersion(),n=!1,this.unsetMatchedCommand());let i={args:this.args,options:this.options};return n&&this.runMatchedCommand(),!this.matchedCommand&&this.args[0]&&this.emit("command:*"),i}mri(t,n){let e=[...this.globalCommand.options,...n?n.options:[]],i=R(e),s=[],r=t.indexOf("--");r>-1&&(s=t.slice(r+1),t=t.slice(0,r));let c=U(t,i);c=Object.keys(c).reduce((m,u)=>g(g({},m),{[D(u)]:c[u]}),{_:[]});let l=c._,a={"--":s},h=n&&n.config.ignoreOptionDefaultValue?n.config.ignoreOptionDefaultValue:this.globalCommand.config.ignoreOptionDefaultValue,f=Object.create(null);for(let m of e){if(!h&&m.config.default!==void 0)for(let u of m.names)a[u]=m.config.default;Array.isArray(m.config.type)&&f[m.name]===void 0&&(f[m.name]=Object.create(null),f[m.name].shouldTransform=!0,f[m.name].transformFunction=m.config.type[0])}for(let m of Object.keys(c))if(m!=="_"){let u=m.split(".");I(a,u,c[m]),S(a,f)}return{args:l,options:a}}runMatchedCommand(){let{args:t,options:n,matchedCommand:e}=this;if(!e||!e.commandAction)return;e.checkUnknownOptions(),e.checkOptionValue(),e.checkRequiredArgs();let i=[];return e.args.forEach((s,r)=>{s.variadic?i.push(t.slice(r)):i.push(t[r])}),i.push(n),e.commandAction.apply(this,i)}},F=(o="")=>new $(o),V=F;var w=V(_chunkXTOXOMLSjs.b);w.command("<template> [project]","Create new project from a template").option("-f, --force","Overwrite if the target exists").option("-o, --offline","Try to use an offline template").allowUnknownOptions().example(" # with an official template").example( $ ${_chunkXTOXOMLSjs.b} [project]).example(" # with a custom github repo").example( $ ${_chunkXTOXOMLSjs.b} / [project]`).action(_chunkXTOXOMLSjs.j);w.command("list [owner]","Show all available templates").alias("ls").option("-j, --json","Output with json format").option("-s, --short","Output with short format").action(_chunkXTOXOMLSjs.h);w.help().version(_chunkXTOXOMLSjs.c).parse();var T=o=>{w.options.debug&&console.error(o),console.error("Exception occurred: "+o.message),process.exit(1)};process.on("uncaughtException",T);process.on("unhandledRejection",T);
^

p: missing required args for command <template> [project]
at b.checkRequiredArgs (/opt/homebrew/lib/node_modules/caz/dist/cli.js:9:213)
at $.runMatchedCommand (/opt/homebrew/lib/node_modules/caz/dist/cli.js:9:3675)
at $.parse (/opt/homebrew/lib/node_modules/caz/dist/cli.js:9:2724)
at Object. (/opt/homebrew/lib/node_modules/caz/dist/cli.js:9:4535)
at Module._compile (node:internal/modules/cjs/loader:1734:14)
at Object..js (node:internal/modules/cjs/loader:1899:10)
at Module.load (node:internal/modules/cjs/loader:1469:32)
at Function._load (node:internal/modules/cjs/loader:1286:12)
at TracingChannel.traceSync (node:diagnostics_channel:322:14)
at wrapModuleLoad (node:internal/modules/cjs/loader:235:24)

Node.js v23.10.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions