Skip to content

Commit a6bf73f

Browse files
DOCSP-11566 allow for users to define their go template (#214)
* DOCSP-11566 allow for users to define their go template DOCSP-11566 self-review * DOCSP-11566 updates for tech review feedback * Update source/configure/go-template-output.txt Co-authored-by: jwilliams-mongo <[email protected]> * DOCSP-11566 update for self-review Co-authored-by: jwilliams-mongo <[email protected]>
1 parent 784635d commit a6bf73f

File tree

3 files changed

+89
-2
lines changed

3 files changed

+89
-2
lines changed

source/configure.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Configure the {+mcli+}
2020
/configure/configuration-file
2121
/configure/environment-variables
2222
/configure/autocomplete
23+
/configure/go-template-output
2324

2425
You can define the settings that the {+mcli+} uses to interact with
2526
MongoDB services like |service|, |cloud-short|, and |onprem| by using
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
.. _go-template-output:
2+
3+
====================================================
4+
Customize the {+mcli+} Output Using a Go Template
5+
====================================================
6+
7+
You can customize the {+mcli+} output fields and format using a ``Go``
8+
template. The template can be specified with the command for a simple output
9+
or through a separate file for a complex output. For information on the
10+
template, see `Package template <https://golang.org/pkg/text/template/>`__.
11+
For information on the types and properties available for each response, see:
12+
13+
- `Atlas types <https://go.mongodb.org/atlas/mongodbatlas/>`__
14+
- `Clour Manager types <https://go.mongodb.org/ops-manager/opsmngr/>`__
15+
- `Ops Manager types <https://go.mongodb.org/ops-manager/opsmngr/>`__
16+
17+
Syntax
18+
------
19+
20+
You can specify a template with the command using the ``--output`` or
21+
``-o`` option:
22+
23+
.. code-block:: shell
24+
:copyable: false
25+
26+
--output|-o go-template="{{<template>}}"
27+
28+
You can specify a template using a file using the ``--output`` or
29+
``-o`` option:
30+
31+
.. code-block:: shell
32+
:copyable: false
33+
34+
--output|-o go-template-file="<path-to-template-file>"
35+
36+
Examples
37+
--------
38+
39+
.. tabs::
40+
41+
.. tab:: Specify Template With the Command
42+
43+
For example, the following command uses the template to retrieve a
44+
count of the number of projects in the specified organization using the
45+
{+default-profile+}:
46+
47+
.. code-block:: shell
48+
49+
mongocli iam projects ls --orgId 5ab5cedf5g5h5i5j5kl12mn4 -o go-template="Count: {{.TotalCount}}"
50+
51+
The preceding command returns the following output:
52+
53+
.. code-block:: shell
54+
:copyable: false
55+
56+
Count: 2
57+
58+
.. tab:: Specify Template Using a File
59+
60+
For example, consider the following file named ``template.tmpl``:
61+
62+
.. code-block:: shell
63+
64+
Projects: {{range .Results}}{{.ID}} {{end}}
65+
66+
The following command uses the ``template.tmpl`` file to retrieve
67+
the IDs of the projects in the specified organization using the
68+
{+default-profile+}:
69+
70+
.. code-block:: shell
71+
72+
mongocli iam projects ls --orgId 5ab5cedf5g5h5i5j5kl12mn4 -o go-template-file="template.tmpl"
73+
74+
The preceding command returns the following output:
75+
76+
.. code-block:: shell
77+
:copyable: false
78+
79+
Projects: 5e2211c17a3e5a48f5497de3 5f455b39749bea5fb575dccc

source/includes/extracts-basic-options.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
ref: fact-basic-options-output
22
content: |
3-
Command output format. Specify ``json`` for output in |json| format. If
4-
omitted, each command returns output in the default format.
3+
Command output format. Valid values are:
4+
5+
- ``json`` for output in |json| format
6+
- ``go-template`` for custom output using the :ref:`Go template
7+
<go-template-output>`
8+
- ``go-template-file`` for custom output specified using :ref:`Go
9+
template <go-template-output>` file
10+
11+
If omitted, the command returns output in the default format.
512
---
613
ref: fact-basic-options-profile
714
content: |

0 commit comments

Comments
 (0)