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

The CLI silently fails when attempting to use an invalid command #629

Closed
nihalgonsalves opened this issue Oct 23, 2019 · 2 comments
Closed
Labels
cli ktlint command line interface enhancement

Comments

@nihalgonsalves
Copy link

There is no response for invalid commands, nor any indication via the exit code:

$ ktlint -V
0.35.0

$ ktlint foo

$ echo $? 
0  

Expected Behaviour:

A typo or invalid command should generate an error message and return with a non-zero exit code.

@Tapchicoma
Copy link
Collaborator

In your example foo is file pattern ktlint uses to find *.kt files. If you will run with ./ktlint --foo then it will fail execution with Error: Unmatched argument [--foo] and general help.

Imho exit code 0 is valid in ./ktlint foo case as it means no Kotlin files found and everything is ok.

@Tapchicoma Tapchicoma added question cli ktlint command line interface labels Nov 17, 2019
@nihalgonsalves
Copy link
Author

nihalgonsalves commented Nov 18, 2019

@Tapchicoma Thanks for the explanation. However, I still believe that the exit code isn't valid, as top level commands (installGitPreCommitHook, installGitPrePushHook, printAST, applyToIDEA, applyToIDEAProject) exist. Misspelling one of these should not result in a successful exit.

I see why it isn't an easy fix. One option to inform users about a misspelling or invalid command could be to print a warning such as "no files matched" to stderr.

paul-dingemans added a commit to paul-dingemans/ktlint that referenced this issue Jun 30, 2022
paul-dingemans added a commit that referenced this issue Jul 24, 2022
…1537)

* Expand (existing) directory to globs for default kotlin extensions 

* When an (existing) directory (without glob pattern) is specified then only process files with default kotlin extensions in that directory or its subdirectories. This is equivalent to execute ktlint in that directory without specifying any pattern.

Closes #917

* When a glob does not contain an absolute path then do not prefix it with the root directory but instead ensure that it is prefixed it with the "**/" matcher. In this way files directly inside the workdir are matched as well as files in subdirectories of the workdir.

* Print an error message and return with non-zero exit code when no files are found that match with the globs

Closes #629

* Refactor by eliminating variable project2Files

* Refactor to improve readability and consistency

* Extract constants to private values. Align name of test class with production class.

* Remove characters which may cause a problem on Windows

* Normalize paths for Windows build

* Disable tests on Windows using absolute paths as those are not supported by jimfs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli ktlint command line interface enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants