add kwargs for cli output
This commit is contained in:
parent
db2031a14c
commit
72f27f198d
1 changed files with 43 additions and 7 deletions
|
|
@ -166,6 +166,7 @@ def diff(dict1, dict2):
|
|||
keydiff = {
|
||||
key for key in set(dict1.keys()) & set(dict2.keys()) if dict1[key] != dict2[key]
|
||||
}
|
||||
keydiff = sorted(keydiff)
|
||||
|
||||
# diff
|
||||
diff1 = {key: dict1[key] for key in exist_in_dict1}
|
||||
|
|
@ -845,26 +846,57 @@ def merge_lists(original, updated, path=""):
|
|||
# Diff recipe = interactive diff
|
||||
# diff_recipe(master, "v1-v2-v3")
|
||||
# {"key_diff": [master_value, dev_value]}
|
||||
def diff_recipe(args):
|
||||
def diff_recipe(args, **kwargs):
|
||||
' `version 1`'
|
||||
|
||||
master_path = args[0]; versions_to_diff = args[1]
|
||||
vs = versions_to_diff.split("-")
|
||||
|
||||
default_dir = "./server/cofffeemachineConfig/"
|
||||
default_dir = "../server/cofffeemachineConfig/"
|
||||
default_name = "coffeethai02_"
|
||||
|
||||
m_json = open(default_dir+default_name+master_path+".json", "r", encoding="utf-8").read()
|
||||
master_json_diff = json.loads(m_json)
|
||||
|
||||
# flag settings
|
||||
is_flat = None
|
||||
is_nooutput = None
|
||||
|
||||
for key, value in kwargs.items():
|
||||
if key == "flatten":
|
||||
is_flat = True if str(value).lower() == "true" else False
|
||||
if args[2] == "debug":
|
||||
print("Flatten: ", is_flat)
|
||||
elif key == "out":
|
||||
is_nooutput = True if str(value).lower() == "false" else False
|
||||
if args[2] == "debug":
|
||||
print("No output: ", is_nooutput)
|
||||
results = []
|
||||
|
||||
|
||||
if is_nooutput:
|
||||
print("Guide: {key: (master, dev)}")
|
||||
|
||||
try:
|
||||
for v in vs:
|
||||
if is_nooutput:
|
||||
|
||||
if is_flat:
|
||||
print("\n----------------------",master_path+"-"+v,"----------------------\n",diff(flatten(master_json_diff), flatten(json.loads(open(default_dir+default_name+v+".json", "r", encoding="utf-8").read())),)[2], "\n")
|
||||
else:
|
||||
print(diff("\n----------------------",master_path+"-"+v,"----------------------\n",master_json_diff, json.loads(open(default_dir+default_name+v+".json", "r", encoding="utf-8").read()),)[2])
|
||||
continue
|
||||
|
||||
if is_flat:
|
||||
results.append({
|
||||
"diff_between": master_path+"-"+v,
|
||||
"result": diff(flatten(master_json_diff), flatten(json.loads(open(default_dir+default_name+v+".json", "r", encoding="utf-8").read())),)[2]
|
||||
})
|
||||
else:
|
||||
results.append({
|
||||
"diff_between": master_path+"-"+v,
|
||||
"result": diff(master_json_diff, json.loads(open(default_dir+default_name+v+".json", "r", encoding="utf-8").read()),)[2]
|
||||
})
|
||||
except:
|
||||
print("Error diffing file")
|
||||
|
||||
|
|
@ -876,6 +908,10 @@ def diff_recipe(args):
|
|||
with open(default_dir+"/diff/"+r["diff_between"]+".json", "w", encoding="utf-8") as f:
|
||||
json.dump(r["result"], f, indent=2, ensure_ascii=False)
|
||||
|
||||
|
||||
if is_nooutput:
|
||||
print("Guide: {key: (master, dev)}")
|
||||
|
||||
print("OK")
|
||||
|
||||
|
||||
|
|
@ -887,7 +923,7 @@ def main():
|
|||
merge(sys.argv[2:])
|
||||
|
||||
elif command_line == "diff":
|
||||
diff_recipe(sys.argv[2:])
|
||||
diff_recipe(sys.argv[2:], **dict(arg.split("=") for arg in sys.argv[5:]))
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue