Skip to content

Instantly share code, notes, and snippets.

@himanoa
Last active Jan 29, 2022
Embed
What would you like to do?
#!/usr/bin/env python
from argparse import ArgumentParser
import os
import subprocess
def run():
usage = 'Usage: pretty-output <command_name> [...argv]'
argparser = ArgumentParser(usage=usage)
argparser.add_argument('command_name', help='Execute command', nargs="*")
command = " ".join(argparser.parse_args().command_name)
result = subprocess.run(command, stdout = subprocess.PIPE, stderr = subprocess.PIPE, shell=True)
msg = """\
```bash
$ {0}
{1}```""".format(command, result.stdout.decode("utf8"))
print(msg)
if __name__ == '__main__':
run()
@himanoa
Copy link
Author

himanoa commented Jan 28, 2022

How to use

 ✓  pretty-output cargo test
```bash
$ cargo test


running 16 tests
test delete_executor::tests::delete_file_and_parent_directory ... ok
test delete_executor::tests::delete_only_file ... ok
test delete_executor::tests::when_failed_delete_file ... ok
test delete_executor::tests::when_failed_delete_parent_delete_directory ... ok
test scaffold_executor::tests::fsscaffold_executor_execute_is_created_files ... ignored
test markdown::tests::parse_is_return_to_one_scaffold ... ok
test template_repository::tests::test_fstemplate_repository_list_return_to_files ... ignored
test template_repository::tests::test_fstemplate_repository_resolve_return_to_template ... ignored
test template_repository::tests::test_fstemplate_repository_resolve_return_to_template_not_found ... ignored
test template::tests::render_returning_the_foo ... ok
test commands::delete::tests::success_delete_command ... ok
test template::tests::render_returning_the_foo_adapter ... ok
test template::tests::render_returning_the_piyopoyo ... ok
test template::tests::render_returning_the_himanoa ... ok
test template::tests::render_returning_the_variable ... ok
test template::tests::render_returning_helper ... ok

test result: ok. 12 passed; 0 failed; 4 ignored; 0 measured; 0 filtered out; finished in 0.00s


running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s


running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

\```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment