|
1 |
| -import sys |
| 1 | +def load_key_value_pair(s): |
| 2 | + items = s.split("=") |
| 3 | + key = items[0].strip() |
| 4 | + if len(items) > 1: |
| 5 | + value = "=".join(items[1:]) |
| 6 | + return (key, value) |
2 | 7 |
|
3 | 8 |
|
4 | 9 | def load_user_metadata(args):
|
5 | 10 | if args.user_metadata:
|
6 | 11 | for item in args.user_metadata:
|
7 |
| - if not item: |
8 |
| - sys.exit( |
9 |
| - "please provide at least one key-value pair in the format key=value. " |
10 |
| - "you can exclude -add if you don't want to provide additional info." |
11 |
| - ) |
12 | 12 | if "=" not in item:
|
13 |
| - sys.exit("please provide key-value pairs in the format key=value.") |
14 |
| - key, value = item.split("=", 1) |
15 |
| - # if "=" in value: |
16 |
| - # sys.exit("please use only one equals sign for key=value.") |
| 13 | + raise ValueError("please provide key-value pairs in the format key=value.") |
| 14 | + key, value = load_key_value_pair(item) |
17 | 15 | setattr(args, key, value)
|
18 | 16 | delattr(args, "user_metadata")
|
19 | 17 | return args
|
| 18 | + |
| 19 | + |
| 20 | +# Notes, can ignore |
| 21 | +# ideal inputs: "key1=value1" "key2=value2" |
| 22 | +# (different pairs are separated by white spaces, key and value are separated by =) |
| 23 | + |
| 24 | +# question 1: white spaces in key, value, both? |
| 25 | +# if value contains whitespace, you can specify key="value value" or "key=value value" |
| 26 | +# if key contains whitespace, for example, you have "key key=value", |
| 27 | +# then you can access like getattr(args, 'key key'), but we dont recommend this |
| 28 | + |
| 29 | +# question 2: more than one =? |
| 30 | +# if i have key is hello, value is hello=world, then i can have hello=hello=world to process okay |
| 31 | +# if i have = in key then it's still processing as value => would this be an issue? |
0 commit comments