pactree: Improve command line validation

Message ID 20200306021037.66811-1-jakseb.dev@gmail.com
State New
Headers show
Series
  • pactree: Improve command line validation
Related show

Commit Message

Sebastian Jakubiak March 6, 2020, 2:10 a.m. UTC
Exit with non-zero status when the command line specifies more
than one package or an unknown option.

Fixes FS#64589.

Signed-off-by: Sebastian Jakubiak <jakseb.dev@gmail.com>
---

If I may, I would like to use this occasion to suggest a feature: the
ability to process multiple packages by pactree. I am sending a patch
for that in reply to this email.

 src/pactree.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Daniel M. Capella March 6, 2020, 11:37 p.m. UTC | #1
On March 5, 2020 9:10:37 PM EST, Sebastian Jakubiak <jakseb.dev@gmail.com> wrote:
> Exit with non-zero status when the command line specifies more
> than one package or an unknown option.
> 
> Fixes FS#64589.
> 
> Signed-off-by: Sebastian Jakubiak <jakseb.dev@gmail.com>
> ---
> 
> If I may, I would like to use this occasion to suggest a feature: the
> ability to process multiple packages by pactree. I am sending a patch
> for that in reply to this email.
> 
>  src/pactree.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/src/pactree.c b/src/pactree.c
> index 5bc0032..9f074fe 100644
> --- a/src/pactree.c
> +++ b/src/pactree.c
> @@ -346,7 +346,6 @@ static int parse_options(int argc, char *argv[])
>  				version();
>  				cleanup(0);
>  			case 'h':
> -			case '?':
>  				usage();
>  				cleanup(0);
>  			default:
> @@ -355,7 +354,8 @@ static int parse_options(int argc, char *argv[])
>  		}
>  	}
>  
> -	if(!argv[optind]) {
> +	if(!argv[optind] || argv[optind + 1]) {
> +		usage();
>  		return 1;
>  	}
>  

Pushed, thank you.

--
Best,
Daniel <https://danielcapella.com>

Patch

diff --git a/src/pactree.c b/src/pactree.c
index 5bc0032..9f074fe 100644
--- a/src/pactree.c
+++ b/src/pactree.c
@@ -346,7 +346,6 @@  static int parse_options(int argc, char *argv[])
 				version();
 				cleanup(0);
 			case 'h':
-			case '?':
 				usage();
 				cleanup(0);
 			default:
@@ -355,7 +354,8 @@  static int parse_options(int argc, char *argv[])
 		}
 	}
 
-	if(!argv[optind]) {
+	if(!argv[optind] || argv[optind + 1]) {
+		usage();
 		return 1;
 	}