Skip to content

Commit

Permalink
Fixed Issue #4: Dealing with complex EDITOR environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
gnebbia committed Sep 18, 2020
1 parent eff10e2 commit 699ba35
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 73 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ source ~/.kb_alias
```

**Tip** for Windows users: Do not use notepad as %EDITOR%, kb is not
compatible with notepad, a reasonable alternative is notepadd++.
compatible with notepad, a reasonable alternative is notepad++.

## USAGE

Expand Down
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# TODO List

- add option to export only data directory containing cheatsheet
- Write installation procedure for Windows
- Fix windows hell with automatic extensions...
- find a way to include complex artifacts
Expand Down
140 changes: 70 additions & 70 deletions kb/cl_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,49 +145,6 @@ def parse_args(args):
default=False,
)

# update parser
update_parser.add_argument(
"-i", "--id",
help="ID of the artifact to update",
type=str,
)
update_parser.add_argument(
"-t", "--title",
help="Title to update",
default=None,
type=str,
)
update_parser.add_argument(
"-c", "--category",
help="Category to update",
default=None,
type=str,
)
update_parser.add_argument(
"-g", "--tags",
help="Tags to update in the form \"tag1;tag2;...;tagN\"",
default=None,
type=str,
)
update_parser.add_argument(
"-a", "--author",
help="Author to update",
default=None,
type=str,
)
update_parser.add_argument(
"-s", "--status",
help="Status to update",
default=None,
type=str,
)
update_parser.add_argument(
"-x", "--edit-content",
help="Edit content of the artifact",
default=None,
type=str,
)

# list parser
list_parser.add_argument(
"query",
Expand Down Expand Up @@ -237,26 +194,6 @@ def parse_args(args):
default=False,
)

# delete parser
delete_parser.add_argument(
"-i", "--id",
help="ID of the artifact",
type=str,
nargs='*',
)
delete_parser.add_argument(
"-t", "--title",
help="Title of the artifact to remove",
default=None,
type=str,
)
delete_parser.add_argument(
"-c", "--category",
help="Category associated to the artifact to remove",
default=None,
type=str,
)

# view parser
view_parser.add_argument(
"-i", "--id",
Expand Down Expand Up @@ -349,13 +286,67 @@ def parse_args(args):
default=False,
)

# erase parser
erase_parser.add_argument(
"--db",
help="Only remove kb database",
action='store_true',
dest='db',
default=False,
# update parser
update_parser.add_argument(
"-i", "--id",
help="ID of the artifact to update",
type=str,
)
update_parser.add_argument(
"-t", "--title",
help="Title to update",
default=None,
type=str,
)
update_parser.add_argument(
"-c", "--category",
help="Category to update",
default=None,
type=str,
)
update_parser.add_argument(
"-g", "--tags",
help="Tags to update in the form \"tag1;tag2;...;tagN\"",
default=None,
type=str,
)
update_parser.add_argument(
"-a", "--author",
help="Author to update",
default=None,
type=str,
)
update_parser.add_argument(
"-s", "--status",
help="Status to update",
default=None,
type=str,
)
update_parser.add_argument(
"-x", "--edit-content",
help="Edit content of the artifact",
default=None,
type=str,
)

# delete parser
delete_parser.add_argument(
"-i", "--id",
help="ID of the artifact",
type=str,
nargs='*',
)
delete_parser.add_argument(
"-t", "--title",
help="Title of the artifact to remove",
default=None,
type=str,
)
delete_parser.add_argument(
"-c", "--category",
help="Category associated to the artifact to remove",
default=None,
type=str,
)

# import parser
Expand All @@ -373,6 +364,15 @@ def parse_args(args):
nargs="?"
)

# erase parser
erase_parser.add_argument(
"--db",
help="Only remove kb database",
action='store_true',
dest='db',
default=False,
)

if len(args) == 0:
parser.print_help(sys.stderr)
sys.exit(1)
Expand Down
2 changes: 1 addition & 1 deletion kb/commands/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ 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
call([config["EDITOR"], Path(category_path, title)])
call([config["EDITOR"], Path(category_path, title)], shell=True)

new_artifact = Artifact(
id=None, title=title, category=category,
Expand Down
2 changes: 1 addition & 1 deletion kb/commands/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def edit(args: Dict[str, str], config: Dict[str, str]):

category_path = Path(config["PATH_KB_DATA"], artifact.category)

call([config["EDITOR"], Path(category_path, artifact.title)])
call([config["EDITOR"], Path(category_path, artifact.title)], shell=True)

# else if a title is specified
elif args["title"]:
Expand Down

0 comments on commit 699ba35

Please sign in to comment.