From 0dc020037507be0e58bf68d4c4bd9e2913b3f3f8 Mon Sep 17 00:00:00 2001 From: nicolargo Date: Sun, 8 Oct 2023 18:55:54 +0200 Subject: [PATCH] Refactor glances.main.GlancesMain.parse_args() --- glances/main.py | 127 +++++++++++++++++++++++++++++------------------- 1 file changed, 77 insertions(+), 50 deletions(-) diff --git a/glances/main.py b/glances/main.py index ead588d1..aa7c58d6 100644 --- a/glances/main.py +++ b/glances/main.py @@ -12,6 +12,8 @@ import argparse import sys import tempfile +from logging import DEBUG +from warnings import simplefilter from glances import __version__, psutil_version from glances.globals import WINDOWS, disable, enable @@ -121,12 +123,17 @@ Examples of use: parser.add_argument( '--disable-plugin', '--disable-plugins', + '--disable', dest='disable_plugin', help='disable plugin (comma separated list or all). If all is used, \ then you need to configure --enable-plugin.', ) parser.add_argument( - '--enable-plugin', '--enable-plugins', dest='enable_plugin', help='enable plugin (comma separated list)' + '--enable-plugin', + '--enable-plugins', + '--enable', + dest='enable_plugin', + help='enable plugin (comma separated list)' ) parser.add_argument( '--disable-process', @@ -533,36 +540,28 @@ Examples of use: return parser - def parse_args(self): - """Parse command line arguments.""" - args = self.init_args().parse_args() - - # Load the configuration file, if it exists - # This function should be called after the parse_args - # because the configuration file path can be defined - self.config = Config(args.conf_file) - - # Debug mode + def init_debug(self, args): + """Init Glances debug mode.""" if args.debug: - from logging import DEBUG - logger.setLevel(DEBUG) else: - from warnings import simplefilter - simplefilter("ignore") - # Plugins refresh rate + def init_refresh_rate(self, args): + """Init Glances refresh rate""" if self.config.has_section('global'): global_refresh = self.config.get_float_value('global', 'refresh', default=self.DEFAULT_REFRESH_TIME) else: global_refresh = self.DEFAULT_REFRESH_TIME - # The configuration key can be overwrite from the command line + + # The configuration key can be overwrite from the command line (-t