-
Notifications
You must be signed in to change notification settings - Fork 129
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
Unify 'help' and 'version' commands #454
Conversation
64436a3
to
eee829d
Compare
closes #259 |
@romanowski should we also support single-hyphen command? |
I think |
eee829d
to
df2d3e8
Compare
I don't really mind… It could be added if we supported |
This is quite interesting, because we support single-hyphen commands only in order to keep compatibility with |
918459d
to
dfa2843
Compare
dfa2843
to
cc24de8
Compare
import scala.build.internal | ||
//import scala.cli.commands.SharedOptions | ||
|
||
case class DefaultOptions( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT We could move that to its own file, like the other options.
@@ -3,28 +3,48 @@ package scala.cli.commands | |||
import caseapp._ | |||
import caseapp.core.Error | |||
|
|||
import scala.build.internal | |||
//import scala.cli.commands.SharedOptions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT
//import scala.cli.commands.SharedOptions |
object DefaultOptions { | ||
implicit lazy val parser: Parser[DefaultOptions] = Parser.derive | ||
implicit lazy val help: Help[DefaultOptions] = Help.derive | ||
// implicit lazy val jsonCodec: ReadWriter[DefaultOptions] = macroRW |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// implicit lazy val jsonCodec: ReadWriter[DefaultOptions] = macroRW |
case class DefaultOptions( | ||
@Recurse | ||
runOptions: RunOptions = RunOptions(), | ||
version: Option[Boolean] = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, I we want to support -version
(single dash), I think the following would work
version: Option[Boolean] = None | |
@Name("-version") | |
version: Option[Boolean] = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why an Option[Boolean]
? A simple Boolean
should do (defaulting to false
).
def run(options: RunOptions, args: RemainingArgs): Unit = | ||
if (anyArgs) | ||
def run(options: DefaultOptions, args: RemainingArgs): Unit = | ||
if (options.version.isDefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this remains an Option
, we should check its value like
if (options.version.isDefined) { | |
if (options.version.contains(true)) { |
Otherwise, --version=false
would make it print the version nonetheless.
def run(options: DefaultOptions, args: RemainingArgs): Unit = | ||
if (options.version.isDefined) { | ||
println(internal.Constants.version) | ||
sys.exit(0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need of the sys.exit
it seems.
sys.exit(0) |
import caseapp._ | ||
|
||
import scala.cli.ScalaCli | ||
case class HelpOptions() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just like for the other options, this can be moved to its own file.
modules/cli/src/main/scala/scala/cli/commands/ScalaCommand.scala
Outdated
Show resolved
Hide resolved
Co-authored-by: Alexandre Archambault <alexarchambault@users.noreply.github.com>
109ca32
to
d4b783c
Compare
|
||
import caseapp._ | ||
|
||
case class HelpOptions() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
case class HelpOptions() | |
@HelpMessage("Print help message") | |
case class HelpOptions() |
This should give a description to the help
command in the help message, like
Other commands:
bsp Start BSP server
export Export current project to sbt or Mill
help Print help message
install completions, install-completions Installs completions into your shell
setup-ide Generate a BSP file that you can import into your IDE
shebang This command is an equivalent of `run`, but it changes the way how
update Update scala-cli - it works only for installation script
pprint.log(os.proc(TestUtil.cli, helpOption).call( | ||
check = false, | ||
mergeErrIntoOut = true | ||
).out.text()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this just for debugging?
pprint.log(os.proc(TestUtil.cli, helpOption).call( | |
check = false, | |
mergeErrIntoOut = true | |
).out.text()) |
// tests if the format is correct instead of comparing to a version passed via Constants | ||
// in order to catch errors in Mill configuration, too | ||
val versionRegex = ".*\\d+[.]\\d+[.]\\d+.*".r | ||
for { versionOption <- Seq("version", "--version") } { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT
for { versionOption <- Seq("version", "--version") } { | |
for (versionOption <- Seq("version", "--version")) { |
No description provided.