URL: https://github.com/freeipa/freeipa/pull/247
Author: tiran
 Title: #247: Add 'ipa show_env' subcommand
Action: opened

PR body:
"""
ipa show_env simply dumps all values from api.env as sorted key="value"
pairs. It's a convenient helper for debugging and to write tests for
e.g. PR #182.

https://fedorahosted.org/freeipa/ticket/6490

Signed-off-by: Christian Heimes <chei...@redhat.com>
"""

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/247/head:pr247
git checkout pr247
From 9a4fe5c5d85a83ca08cb4bdf85edd7e4780d0ce0 Mon Sep 17 00:00:00 2001
From: Christian Heimes <chei...@redhat.com>
Date: Wed, 16 Nov 2016 13:53:42 +0100
Subject: [PATCH] Add 'ipa show_env' subcommand

ipa show_env simply dumps all values from api.env as sorted key="value"
pairs. It's a convenient helper for debugging and to write tests for
e.g. PR #182.

https://fedorahosted.org/freeipa/ticket/6490

Signed-off-by: Christian Heimes <chei...@redhat.com>
---
 client/man/ipa.1 |  6 +++++-
 ipalib/cli.py    | 24 ++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/client/man/ipa.1 b/client/man/ipa.1
index 9194ca0..a714eda 100644
--- a/client/man/ipa.1
+++ b/client/man/ipa.1
@@ -65,13 +65,17 @@ The principal function of the CLI is to execute administrative commands specifie
 
 From the implementation perspective, the CLI distinguishes two types of commands \- built\-ins and plugin provided.
 
-Built\-in commands are static and are all available in all installations of IPA. There are two of them:
+Built\-in commands are static and are all available in all installations of IPA. There are three of them:
 .TP
 \fBconsole\fR
 Start the IPA interactive Python console.
 .TP
 \fBhelp\fR [\fITOPIC\fR | \fICOMMAND\fR | \fBtopics\fR | \fBcommands\fR]
 Display help for a command or topic.
+\fBshow_env\fR
+Show local IPA api.env values.
+.TP
+
 
 The \fBhelp\fR command invokes the built\-in documentation system. Without parameters a list of built\-in commands and help topics is displayed. Help topics are generated from loaded IPA plugin modules. Executing \fBhelp\fR with the name of an available topic displays a help message provided by the corresponding plugin module and list of commands it contains.
 .LP
diff --git a/ipalib/cli.py b/ipalib/cli.py
index 05bc0f5..35206de 100644
--- a/ipalib/cli.py
+++ b/ipalib/cli.py
@@ -54,6 +54,7 @@
 from ipalib.parameters import File, Str, Enum, Any, Flag
 from ipalib.text import _
 from ipalib import api  # pylint: disable=unused-import
+from ipapython.dn import DN
 from ipapython.dnsutil import DNSName
 
 import datetime
@@ -859,6 +860,28 @@ def print_commands(self, topic, outfile):
                 writer(_('  ipa <command> --help'))
             writer()
 
+
+class show_env(frontend.Local):
+    """Dump api.env vars
+    """
+
+    takes_args = ()
+    takes_options = ()
+    has_output = ()
+    topic = None
+
+    def run(self, *args, **options):
+        for key in sorted(self.api.env):
+            value = getattr(api.env, key)
+            if isinstance(value, DN):
+                value = unicode(value)
+            if isinstance(value, (str, unicode)):
+                # shell escape
+                value = value.replace(r'"', r'\"')
+                value = value.replace('$', r'$$')
+            print('{}="{}"'.format(key, value))
+
+
 class show_mappings(frontend.Command):
     """
     Show mapping of LDAP attributes to command-line option.
@@ -1336,6 +1359,7 @@ def format_description(self, description):
     console,
     help,
     show_mappings,
+    show_env,
 )
 
 
-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to