cqi / rpms / fedpkg

Forked from rpms/fedpkg 6 years ago
Clone
Blob Blame History Raw
From 4ee70510c86469b2b1f910ad85844e7bce9b94a8 Mon Sep 17 00:00:00 2001
From: Chenxiong Qi <cqi@redhat.com>
Date: Mon, 21 May 2018 23:22:59 +0800
Subject: [PATCH] Fix argparse error in Python 3

argparse behaves differently in Python 2 and 3 when no options and
arguments are passed to executable fedpkg. That causes no attribute
named command is set to parsed namespace object in Python 3. Command
line help message has to be output explicitly.

Fixes #221

Signed-off-by: Chenxiong Qi <cqi@redhat.com>
---
 fedpkg/__main__.py | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/fedpkg/__main__.py b/fedpkg/__main__.py
index e12f255..c7ea14c 100644
--- a/fedpkg/__main__.py
+++ b/fedpkg/__main__.py
@@ -57,6 +57,14 @@ def main():
     client.do_imports(site='fedpkg')
     client.parse_cmdline()
 
+    # This is due to a difference argparse behavior to Python 2 version.
+    # In Python 3, argparse will proceed to here without reporting
+    # "too few arguments". Instead, client.args does not have attribute
+    # command.
+    if not hasattr(client.args, 'command'):
+        client.parser.print_help()
+        sys.exit(1)
+
     if not client.args.path:
         try:
             client.args.path = pyrpkg.utils.getcwd()
-- 
2.14.3