Skip to content

Commit 7ff189a

Browse files
authored
default to std out for moban cli - a single rendering target (#391)
* ✨ print to stdout if it is a single render action. resolves #390 * ✨ error output to stderr. at cli, pipe output won't accidentally get the error message. user can use shell stderr direction to get error message * 📚 update readme * :greenheart: make ci pass by update unit tests
1 parent 1aa4785 commit 7ff189a

File tree

16 files changed

+182
-131
lines changed

16 files changed

+182
-131
lines changed

.moban.cd/changelog.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
name: moban
22
organisation: moremoban
33
releases:
4+
- changes:
5+
- action: Updated
6+
details:
7+
- "`#390`: single render action will print to stdout by defafult"
8+
date: 06.08.2020
9+
version: 0.7.9
410
- changes:
511
- action: Added
612
details:

.moban.cd/moban.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ organisation: moremoban
44
author: C. W.
55
66
license: MIT
7-
version: 0.7.8
8-
current_version: 0.7.8
9-
release: 0.7.8
7+
version: 0.7.9
8+
current_version: 0.7.9
9+
release: 0.7.9
1010
branch: master
1111
master: index
1212
command_line_interface: "moban"

.moban.d/moban_readme.jj2

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,11 @@ versions lower than 0.7.0 if you are still using python 2.
4444
Quick start
4545
================================================================================
4646

47-
.. image:: https://github.com/moremoban/moban/raw/dev/docs/images/moban-in-intro.gif
48-
4947
{% raw %}
5048
.. code-block:: bash
5149

5250
$ export HELLO="world"
5351
$ moban "{{HELLO}}"
54-
Templating {{HELLO}}... to moban.output
55-
Templated 1 file.
56-
$ cat moban.output
5752
world
5853

5954
Or
@@ -76,7 +71,6 @@ A bit formal example:
7671
.. code-block:: bash
7772

7873
$ moban -c data.yml -t my.template
79-
$ cat moban.output
8074

8175
Given data.yml as:
8276

CHANGELOG.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
Change log
22
================================================================================
33

4+
0.7.9 - 06.08.2020
5+
--------------------------------------------------------------------------------
6+
7+
**Updated**
8+
9+
#. `#390 <https://github.com/moremoban/moban/issues/390>`_: single render action
10+
will print to stdout by defafult
11+
412
0.7.8 - 09.06.2020
513
--------------------------------------------------------------------------------
614

README.rst

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,11 @@ versions lower than 0.7.0 if you are still using python 2.
4444
Quick start
4545
================================================================================
4646

47-
.. image:: https://github.com/moremoban/moban/raw/dev/docs/images/moban-in-intro.gif
48-
4947

5048
.. code-block:: bash
5149
5250
$ export HELLO="world"
5351
$ moban "{{HELLO}}"
54-
Templating {{HELLO}}... to moban.output
55-
Templated 1 file.
56-
$ cat moban.output
5752
world
5853
5954
Or
@@ -75,7 +70,6 @@ A bit formal example:
7570
.. code-block:: bash
7671
7772
$ moban -c data.yml -t my.template
78-
$ cat moban.output
7973
8074
Given data.yml as:
8175

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
copyright = '2017-2020 Onni Software Ltd.'
2626
author = 'C. W.'
2727
# The short X.Y version
28-
version = '0.7.8'
28+
version = '0.7.9'
2929
# The full version, including alpha/beta/rc tags
30-
release = '0.7.8'
30+
release = '0.7.9'
3131

3232
# -- General configuration ---------------------------------------------------
3333

moban/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
__version__ = "0.7.8"
1+
__version__ = "0.7.9"
22
__author__ = "C. W."

moban/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
file_system.path_join(".", DEFAULT_TEMPLATE_DIRNAME),
5757
],
5858
# moban.output, default output file name
59-
LABEL_OUTPUT: "%s.output" % PROGRAM_NAME,
59+
LABEL_OUTPUT: "-",
6060
# data.yml, default data input file
6161
LABEL_CONFIG: "data%s" % DEFAULT_YAML_SUFFIX,
6262
LABEL_TEMPLATE_TYPE: DEFAULT_TEMPLATE_TYPE,

moban/externals/buffered_writer.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ def __init__(self):
1111
self.fs_list = {}
1212

1313
def write_file_out(self, filename, content):
14-
if file_system.is_zip_alike_url(filename):
14+
if filename == "-":
15+
print(content.decode())
16+
elif file_system.is_zip_alike_url(filename):
1517
self.write_file_out_to_zip(filename, content)
1618
else:
1719
write_file_out(filename, content)

moban/externals/reporter.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import sys
2+
13
import crayons
24

35
import moban.constants as constants
@@ -13,6 +15,8 @@
1315
MESSAGE_FILE_EXTENSION_NOT_NEEDED = "File extension is not required for ad-hoc\
1416
type"
1517

18+
GLOBAL = {"PRINT": True}
19+
1620

1721
def report_templating(
1822
action_in_present_continuous_tense, source_file, destination_file
@@ -49,11 +53,13 @@ def report_partial_run(action_in_past_tense, file_count, total):
4953

5054

5155
def report_error_message(message):
52-
do_print(crayons.white("Error: ", bold=True) + crayons.red(message))
56+
error_print(crayons.white("Error: ", bold=True) + crayons.red(message))
5357

5458

5559
def report_warning_message(message):
56-
do_print(crayons.white("Warning: ", bold=True) + crayons.yellow(message))
60+
error_print(
61+
crayons.white("Warning: ", bold=True) + crayons.yellow(message)
62+
)
5763

5864

5965
def report_info_message(message):
@@ -98,4 +104,9 @@ def report_file_extension_not_needed():
98104

99105

100106
def do_print(message):
101-
print(message)
107+
if GLOBAL["PRINT"]:
108+
print(message)
109+
110+
111+
def error_print(message):
112+
sys.stderr.write(message + "\n")

0 commit comments

Comments
 (0)