Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: update cli options help #246

Merged
merged 5 commits into from May 3, 2024
Merged

Conversation

nobkd
Copy link
Collaborator

@nobkd nobkd commented Mar 28, 2024

@tipiirai tipiirai marked this pull request as ready for review March 29, 2024 06:55
@tipiirai
Copy link
Contributor

Thanks!

Is this still a work in progress? What are those "x" entries? If unaware:

--dry-run only shows what is being build, but does not do anything
--esbuild uses esbuild instead of Bun bundler for bundling/minifyin javascript

@nobkd
Copy link
Collaborator Author

nobkd commented Mar 29, 2024

Yeah, it's work in progress. The xes are placeholders, because I haven't had read the code for those options. I also wanted to first check, if esbuild was a hard dependency now. If not, it would have to be mentioned in the description. Had no time yesterday and today, so the pr has to wait :)

@nobkd
Copy link
Collaborator Author

nobkd commented Mar 29, 2024

What about the order of the options? Just did it now, as I thought would be relevant 🤷


Also, I see some possible problems with the current option parsing:

} else if (arg[0] == '-') {

What if a file path for an option or for paths starts with a -?
(Also paths with spaces, whether in quotes or not, won't work. If the paths are ever used by anyone) (Edit: I think the shell should handle these)


else if (opt) throw `"${opt}" option is not set`

Probably won't ever happen, because the if-switch won't ever get there when another option was set.

nue -r -s myroot somepath -> would work, as root is taken, but is unexpected, because root comes after another option

nue -e -s -> won't error too, as another option was set, and the opt is never checked again

@nobkd
Copy link
Collaborator Author

nobkd commented Mar 29, 2024

I don't think, it's correct that -n / --dry-run only works with build command set, and is ignored for no command, serve and stats

Important

Will have to add that to the description, if that's correct like that

Will have to check, if it's maybe just my current project...

@nobkd nobkd marked this pull request as draft March 30, 2024 02:52
@nobkd
Copy link
Collaborator Author

nobkd commented Apr 3, 2024

My diff idea for this (#246 (comment)) would be

// options
} else if (arg[0] == '-') {
// booleans
if (['-p', '--production'].includes(arg)) args.is_prod = true
else if (['-v', '--version'].includes(arg) && !args.cmd) args.version = true
else if (['-n', '--dry-run'].includes(arg)) args.dryrun = true
else if (['-h', '--help'].includes(arg)) args.help = true
else if (['-v', '--verbose'].includes(arg)) args.verbose = true
else if (['-s', '--stats'].includes(arg)) args.stats = true
else if (['-b', '--esbuild'].includes(arg)) args.esbuild = true
else if (['-P', '--push'].includes(arg)) args.push = true
else if (['-I', '--init'].includes(arg)) args.init = true
// string values
else if (['-e', '--environment'].includes(arg)) opt = 'env'
else if (['-r', '--root'].includes(arg)) opt = 'root'
// bad options
else if (opt) throw `"${opt}" option is not set`
else throw `Unknown option: "${arg}"`
} else if (arg) {
if (opt) { args[opt] = arg; opt = null }
else args.paths.push(arg)
}
})
return args
}

     // options
-    } else if (arg[0] == '-') {
+    } else if (!opt && arg[0] == '-') {

       // booleans
       if (['-p', '--production'].includes(arg)) args.is_prod = true
       else if (['-v', '--version'].includes(arg) && !args.cmd) args.version = true
       else if (['-n', '--dry-run'].includes(arg)) args.dryrun = true
       else if (['-h', '--help'].includes(arg)) args.help = true
       else if (['-v', '--verbose'].includes(arg)) args.verbose = true
       else if (['-s', '--stats'].includes(arg)) args.stats = true
       else if (['-b', '--esbuild'].includes(arg)) args.esbuild = true
       else if (['-P', '--push'].includes(arg)) args.push = true
       else if (['-I', '--init'].includes(arg)) args.init = true
 
       // string values
       else if (['-e', '--environment'].includes(arg)) opt = 'env'
       else if (['-r', '--root'].includes(arg)) opt = 'root'
 
       // bad options
-      else if (opt) throw `"${opt}" option is not set`
       else throw `Unknown option: "${arg}"`
 
     } else if (arg) {
       if (opt) { args[opt] = arg; opt = null }
       else args.paths.push(arg)
-    }
+    } else if (opt) throw `"${opt}" option is not set`
   })
 
   return args
 }

Problem is, that option is not set still does not happen, if we have a command not having any arguments left after an option requiring an argument e.g. cmd nue -e --> no args left, quits parsing

@tipiirai
Copy link
Contributor

tipiirai commented Apr 8, 2024

Yeah. Clearly some issues in there with special file names and need to be fixed somehow. I think filenames starting with "-" are not a priority atm.

@nobkd
Copy link
Collaborator Author

nobkd commented Apr 30, 2024

Okay... I started looking here again. And --dry-run only works with build / push / provided file to build:

else if (push || args.paths[0] || cmd == 'build') {
const paths = await nue.build(args.paths, dryrun)
// deploy (private repo ATM)
if (!dryrun && push) {
const { deploy } = await import('nue-deployer')
await deploy(paths, { root: nue.dist, init: args.init })
}
// serve
} else await nue.serve()

if (is_empty) await build()

changing the latter to build([], args.dryrun) would stop the files from being built at the start, but I think that is nonsensical.

I think it would be better to just add dry-run to else if (dryrun || push || .... That behaves as being built, and prints what would be built without starting a dev server, that only builds after changing a file, and then only that changed file.

@nobkd
Copy link
Collaborator Author

nobkd commented Apr 30, 2024

--dry-run is incompatible with stats as command and option.
If the .dist / output directory does not exist yet, it even throws an error.

I'll just skip stats printing if dry-run is active, alright?

@nobkd nobkd marked this pull request as ready for review April 30, 2024 20:50
@nobkd
Copy link
Collaborator Author

nobkd commented Apr 30, 2024

I've changed the code according to my ideas. Please let me know if you see potential for improvement.

@nobkd nobkd requested a review from tipiirai April 30, 2024 20:51
@tipiirai tipiirai merged commit 0d3cebc into nuejs:master May 3, 2024
3 checks passed
@tipiirai
Copy link
Contributor

tipiirai commented May 3, 2024

Looks solid. Thank you!

@nobkd nobkd deleted the docs/cli-options branch May 3, 2024 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update CLI help message to represent current options
2 participants