Skip to content

Commit

Permalink
move latest to src and delete from root
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Urbanski committed Feb 5, 2020
1 parent c13e067 commit aed8344
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 92 deletions.
92 changes: 0 additions & 92 deletions click_extensions.py

This file was deleted.

30 changes: 30 additions & 0 deletions src/click_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,34 @@ def convert(self, value, param, ctx):
return value.split(',')


class ClickKeyValue(click.ParamType):
name = "Key=Value"

def convert(self, value, param, ctx):
parts = value.split('=', 1)
if len(parts) < 2:
raise UsageError(f"Invalid argument: {value}: must be in Key=Value form.", ctx=ctx)
return parts[0], parts[1]


class ClickKeyValueCSV(click.ParamType):
name = "Key=Value[,...]"

def convert(self, value, param, ctx):
values = value.split(',')
pairs = []
for v in values:
parts = v.split('=', 1)
if len(parts) < 2:
raise UsageError(f"Invalid argument: {v}: must be in Key=Value form.", ctx=ctx)
pairs.append((parts[0], parts[1]))
return pairs


class ClickRequires(click.ParamType):
pass


CSV = ClickCommaSeparatedList()
KeyValue = ClickKeyValue()
KeyValueCSV = ClickKeyValueCSV()

0 comments on commit aed8344

Please sign in to comment.