Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: body for kb add #28

Merged
merged 1 commit into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions kb/cl_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ def parse_args(args):
help="Status of the artifact",
type=str,
)
add_parser.add_argument(
"-b", "--body",
help="Body of artifact",
type=str,
)

# edit parser
edit_parser.add_argument(
Expand Down
11 changes: 8 additions & 3 deletions kb/commands/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,14 @@ def add(args: Dict[str, str], config: Dict[str, str]):
if not db.is_artifact_existing(conn, title, category):
# If a file is provided, copy the file to kb directory
# otherwise open up the editor and create some content
shell_cmd = shlex.split(
config["EDITOR"]) + [str(Path(category_path, title))]
call(shell_cmd)
if args["body"]:
with open(Path(category_path, title), "w+") as f:
body = args["body"].replace("\\n", "\n")
f.write(body)
else:
shell_cmd = shlex.split(
config["EDITOR"]) + [str(Path(category_path, title))]
call(shell_cmd)

new_artifact = Artifact(
id=None, title=title, category=category,
Expand Down