Fix pldmd verbosity command line argument

This commit would attempt to fix the command line argument --verbose.

The fact that verbose option requires an argument 0 or 1 is not
particularly intuitive and a documented OpenBMC anti-pattern.

https://github.com/openbmc/docs/blob/master/anti-patterns.md#non-standard-debug-application-options-and-logging

Resolves : https://github.com/openbmc/pldm/issues/7
Signed-off-by: Manojkiran Eda <manojkiran.eda@gmail.com>
Change-Id: I50d82ce492bd815b589627d3713b1a7fc1db997b
diff --git a/README.md b/README.md
index 4054da6..b9fe25c 100644
--- a/README.md
+++ b/README.md
@@ -8,6 +8,19 @@
 ```
 meson builddir && meson test -C builddir
 ```
+## To enable pldm verbosity
+pldm daemon accepts a command line argument `--verbose` or `--v` or `-v` to enable the
+daemon to run in verbose mode. It can be done via adding this option to the environment
+file that pldm service consumes.
+```
+echo 'PLDMD_ARGS="--verbose"' > /etc/default/pldmd
+systemctl restart pldmd
+```
+## To disable pldm verbosity
+```
+rm /etc/default/pldmd
+systemctl restart pldmd
+```
 
 Alternatively, tests can be run in the OpenBMC CI docker container, or with an
 OpenBMC x86 sdk(see below for x86 steps).
diff --git a/meson.build b/meson.build
index 0e20765..ca005f4 100644
--- a/meson.build
+++ b/meson.build
@@ -52,7 +52,6 @@
   add_project_arguments('-DOEM_IBM', language : 'c')
   add_project_arguments('-DOEM_IBM', language : 'cpp')
 endif
-conf_data.set('PLDM_VERBOSITY',get_option('verbosity'))
 conf_data.set('NUMBER_OF_REQUEST_RETRIES', get_option('number-of-request-retries'))
 conf_data.set('INSTANCE_ID_EXPIRATION_INTERVAL',get_option('instance-id-expiration-interval'))
 conf_data.set('RESPONSE_TIME_OUT',get_option('response-time-out'))
@@ -204,13 +203,6 @@
     output: 'pldmd.service',
   )
 
-  configure_file(
-    input: 'pldmd/verbosity/verbosity',
-    output: 'pldm_verbosity',
-    configuration: conf_data,
-    install: true,
-    install_dir: join_paths(get_option('sysconfdir'), 'default'))
-
   if get_option('oem-ibm').enabled()
     subdir('oem/ibm/service_files')
   endif
diff --git a/meson_options.txt b/meson_options.txt
index 7bb863f..c4a1d59 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -1,5 +1,4 @@
 option('tests', type: 'feature', description: 'Build tests', value: 'enabled')
-option('verbosity',type:'integer',min:0, max:1, description: 'Enables/Disables pldm verbosity',value: 0)
 option('oe-sdk', type: 'feature', description: 'Enable OE SDK')
 option('oem-ibm', type: 'feature', description: 'Enable IBM OEM PLDM')
 option('requester-api', type: 'feature', description: 'Enable libpldm requester API', value: 'enabled')
diff --git a/pldmd/pldmd.cpp b/pldmd/pldmd.cpp
index 1e7cd15..dc0a2bb 100644
--- a/pldmd/pldmd.cpp
+++ b/pldmd/pldmd.cpp
@@ -147,37 +147,25 @@
 {
     std::cerr << "Usage: pldmd [options]\n";
     std::cerr << "Options:\n";
-    std::cerr
-        << "  --verbose=<0/1>  0 - Disable verbosity, 1 - Enable verbosity\n";
-    std::cerr << "Defaulted settings:  --verbose=0 \n";
+    std::cerr << "  [--verbose] - would enable verbosity\n";
 }
 
 int main(int argc, char** argv)
 {
     bool verbose = false;
-    static struct option long_options[] = {
-        {"verbose", required_argument, 0, 'v'}, {0, 0, 0, 0}};
+    static struct option long_options[] = {{"verbose", no_argument, 0, 'v'},
+                                           {0, 0, 0, 0}};
 
-    auto argflag = getopt_long(argc, argv, "v:", long_options, nullptr);
+    auto argflag = getopt_long(argc, argv, "v", long_options, nullptr);
     switch (argflag)
     {
         case 'v':
-            switch (std::stoi(optarg))
-            {
-                case 0:
-                    verbose = false;
-                    break;
-                case 1:
-                    verbose = true;
-                    break;
-                default:
-                    optionUsage();
-                    exit(EXIT_FAILURE);
-            }
+            verbose = true;
             break;
         case -1:
             break;
         default:
+            optionUsage();
             exit(EXIT_FAILURE);
     }
 
diff --git a/pldmd/service_files/pldmd.service b/pldmd/service_files/pldmd.service
index 4eaa706..4972822 100644
--- a/pldmd/service_files/pldmd.service
+++ b/pldmd/service_files/pldmd.service
@@ -7,8 +7,8 @@
 Restart=always
 Type=dbus
 BusName=xyz.openbmc_project.PLDM
-EnvironmentFile=/etc/default/pldm_verbosity
-ExecStart=/usr/bin/pldmd --verbose $VERBOSE
+EnvironmentFile=-/etc/default/pldmd
+ExecStart=/usr/bin/pldmd $PLDMD_ARGS
 
 [Install]
 WantedBy=multi-user.target
diff --git a/pldmd/verbosity/verbosity b/pldmd/verbosity/verbosity
deleted file mode 100644
index 45cf9bf..0000000
--- a/pldmd/verbosity/verbosity
+++ /dev/null
@@ -1 +0,0 @@
-VERBOSE=@PLDM_VERBOSITY@