Skip to content

Commit

Permalink
Clarify argument handling
Browse files Browse the repository at this point in the history
  • Loading branch information
boidolr committed Sep 11, 2017
1 parent 7cd1be9 commit a94231a
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions wordcloud/wordcloud_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,31 +143,29 @@ def parse_args(arguments):
if args.colormask and args.color:
raise ValueError('specify either a color mask or a color function')

with args.text:
args.text = args.text.read()
args = vars(args)

with args.pop('text') as f:
text = f.read()

if args.stopwords:
with args.stopwords:
args.stopwords = set(map(str.strip, args.stopwords.readlines()))
if args['stopwords']:
with args.pop('stopwords') as f:
args['stopwords'] = set(map(str.strip, f.readlines()))

if args.mask:
args.mask = np.array(Image.open(args.mask))
if args['mask']:
mask = args.pop('mask')
args['mask'] = np.array(Image.open(mask))

color_func = wc.random_color_func
if args.colormask:
image = np.array(Image.open(args.colormask))
colormask = args.pop('colormask')
color = args.pop('color')
if colormask:
image = np.array(Image.open(colormask))
color_func = wc.ImageColorGenerator(image)
if color:
color_func = wc.get_single_color_func(color)
args['color_func'] = color_func

if args.color:
color_func = wc.get_single_color_func(args.color)

args.color_func = color_func

args = vars(args)
# remove arguments not directly mapped
_ = args.pop('colormask', None)
_ = args.pop('color', None)
text = args.pop('text')
imagefile = args.pop('imagefile')

return args, text, imagefile
Expand Down

0 comments on commit a94231a

Please sign in to comment.