Skip to content

Commit 4caef75

Browse files
committed
add: body for kb add
1 parent 8e752de commit 4caef75

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

kb/cl_parser.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ def parse_args(args):
100100
help="Status of the artifact",
101101
type=str,
102102
)
103+
add_parser.add_argument(
104+
"-b", "--body",
105+
help="Body of artifact",
106+
type=str,
107+
)
103108

104109
# edit parser
105110
edit_parser.add_argument(

kb/commands/add.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,14 @@ def add(args: Dict[str, str], config: Dict[str, str]):
6969
if not db.is_artifact_existing(conn, title, category):
7070
# If a file is provided, copy the file to kb directory
7171
# otherwise open up the editor and create some content
72-
shell_cmd = shlex.split(
73-
config["EDITOR"]) + [str(Path(category_path, title))]
74-
call(shell_cmd)
72+
if args["body"]:
73+
with open(Path(category_path, title), "w+") as f:
74+
body = args["body"].replace("\\n", "\n")
75+
f.write(body)
76+
else:
77+
shell_cmd = shlex.split(
78+
config["EDITOR"]) + [str(Path(category_path, title))]
79+
call(shell_cmd)
7580

7681
new_artifact = Artifact(
7782
id=None, title=title, category=category,

0 commit comments

Comments
 (0)