-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommout
More file actions
executable file
·22 lines (19 loc) · 808 Bytes
/
commout
File metadata and controls
executable file
·22 lines (19 loc) · 808 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env python3
import click
from plumbum.cmd import grep, cat
@click.command()
@click.argument("filename")
@click.option("--comment-token", "-t", default = "#", show_default=True,
help = "Set the comment token.")
@click.option("--context", "-c", default = 0, show_default=True,
help = "Display N preceding comment line(s).")
@click.option("--no-separators", "-v", is_flag = True,
help = "Avoid displaying context separators.")
def cli(filename, comment_token, context, no_separators):
click.echo(comment_token)
output = (cat[filename] | grep["-v", "^$"] | grep["-v", "^"+comment_token, "-B", context])
if no_separators:
output = (output | grep["-v", "^--"])
click.echo(output())
if __name__ == '__main__':
cli()