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

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 e2aa45a697ff3da8cce98a1d8ba76db09dff86a7 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 localenv' subcommand

ipa local-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.


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..cc5641b 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:
 Start the IPA interactive Python console.
 \fBhelp\fR [\fITOPIC\fR | \fICOMMAND\fR | \fBtopics\fR | \fBcommands\fR]
 Display help for a command or topic.
+Show local IPA api.env values.
 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.
diff --git a/ipalib/cli.py b/ipalib/cli.py
index 05bc0f5..ad876ea 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'))
+class local_env(frontend.Local):
+    """Dump local 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):
+    local_env,
Manage your subscription for the Freeipa-devel mailing list:
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to