-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get a CLI for each subcommand so asciidoc diagrams is easier
- Loading branch information
1 parent
5e6041d
commit 7a58f1e
Showing
4 changed files
with
58 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,3 @@ | ||
import sys | ||
import argparse | ||
from . import constants | ||
from . import spans | ||
from . import cli | ||
|
||
def parse_args(argv): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('file', help='file of operations') | ||
parser.add_argument('-o', '--output', help='output file path') | ||
parser.add_argument('--debug', action='store_true', help='print out each intermediate step') | ||
parser.add_argument('--guidelines', action='store_true', help='add extra lines to debug alignment issues') | ||
parser.add_argument('--embed', action='store_true', help='only use 12px font and px units') | ||
return parser.parse_args() | ||
|
||
def main(argv): | ||
args = parse_args(argv) | ||
|
||
if args.debug: | ||
constants.DEBUG = True | ||
if args.guidelines: | ||
constants.GUIDELINES = True | ||
if args.embed: | ||
constants.EMBED = True | ||
|
||
with open(args.file) as f: | ||
text_input = f.read() | ||
|
||
svg = spans.to_span_svg(text_input) | ||
|
||
if args.output is None or args.output == '-': | ||
sys.stdout.write(svg) | ||
elif args.output.endswith('.svg'): | ||
with open(args.output, 'w') as f: | ||
f.write(svg) | ||
elif args.output.endswith('.png'): | ||
# A yet-to-be-released version of cairosvg is required to correctly | ||
# render the SVGs produced, so make it a runtime requirement. | ||
from cairosvg import svg2png | ||
svg2png(bytestring=svg, write_to=args.output) | ||
|
||
main(sys.argv) | ||
cli.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import sys | ||
import argparse | ||
from . import constants | ||
from . import spans | ||
|
||
def parse_spans_args(parser=None): | ||
parser = parser or argparse.ArgumentParser() | ||
parser.add_argument('file', help='file of operations') | ||
parser.add_argument('-o', '--output', help='output file path') | ||
parser.add_argument('--debug', action='store_true', help='print out each intermediate step') | ||
parser.add_argument('--guidelines', action='store_true', help='add extra lines to debug alignment issues') | ||
parser.add_argument('--embed', action='store_true', help='only use 12px font and px units') | ||
return parser | ||
|
||
def main_spans(args = None): | ||
args = args or parse_spans_args().parse_args() | ||
|
||
if args.debug: | ||
constants.DEBUG = True | ||
if args.guidelines: | ||
constants.GUIDELINES = True | ||
if args.embed: | ||
constants.EMBED = True | ||
|
||
with open(args.file) as f: | ||
text_input = f.read() | ||
|
||
svg = spans.to_span_svg(text_input) | ||
|
||
if args.output is None or args.output == '-': | ||
sys.stdout.write(svg) | ||
elif args.output.endswith('.svg'): | ||
with open(args.output, 'w') as f: | ||
f.write(svg) | ||
elif args.output.endswith('.png'): | ||
# A yet-to-be-released version of cairosvg is required to correctly | ||
# render the SVGs produced, so make it a runtime requirement. | ||
from cairosvg import svg2png | ||
svg2png(bytestring=svg, write_to=args.output) | ||
|
||
def parse_main_args(parser=None): | ||
parser = parser or argparse.ArgumentParser() | ||
subparsers = parser.add_subparsers(required=True) | ||
|
||
spans_parser = subparsers.add_parser('spans') | ||
spans_parser.set_defaults(main_func=main_spans) | ||
parse_spans_args(spans_parser) | ||
|
||
return parser | ||
|
||
def main(): | ||
args = parse_main_args().parse_args() | ||
args.main_func(args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Test suite for the dbdiag package.""" |