Skip to content
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
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ code-lint: ## Lint the code
@echo Pylama...
@if type pylama >/dev/null 2>&1 ; then pylama $(SRC_CORE) ; \
else echo "SKIPPED. Run '$(PIP) install pylama' first." >&2 ; fi
@if type fixit >/dev/null 2>&1 ; then cd $(SRC_CORE) ; fixit run_rules ; \
else echo "SKIPPED. Run '$(PIP) install fixit' first." >&2 ; fi
@echo Pylint...
@if type pylint >/dev/null 2>&1 ; then pylint $(SRC_CORE) ; \
else echo "SKIPPED. Run '$(PIP) install pylint' first." >&2 ; fi
Expand Down
53 changes: 45 additions & 8 deletions things_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
from xml.etree.ElementTree import Element, SubElement

import argcomplete # type: ignore

import things as api

from things_cli import __version__


Expand All @@ -32,13 +32,37 @@ class ThingsCLI: # pylint: disable=R0902
filter_project = None
filter_area = None
filter_tag = None
only_projects = None

def __init__(self, database=None):
"""Initialize class."""
self.database = database

def print_tasks(self, tasks):
"""Print a task."""

if self.only_projects:
for task in tasks:
task["items"] = (
[
items
for items in task["items"]
if items["type"] in ["area", "project"]
]
if task.get("items")
else []
)
for items in task["items"]:
items["items"] = (
[
sub_items
for sub_items in items["items"]
if sub_items["type"] in ["area", "project"]
]
if items.get("items")
else []
)

if self.print_json:
print(json.dumps(tasks))
elif self.print_opml:
Expand Down Expand Up @@ -102,7 +126,12 @@ def opml_convert(self, tasks, top):
return
for task in tasks:
area = SubElement(top, "outline")
area.set("text", task["title"])
text = task["title"]
if task.get("start_date"):
text = f"{text} (Scheduled: {task['start_date']})"
elif task.get("start"):
text = f"{text} ({task['start']})"
area.set("text", text)
self.opml_convert(task.get("items", []), area)
task.pop("items", [])
self.opml_convert(task.get("checklist", []), area)
Expand Down Expand Up @@ -135,7 +164,7 @@ def txt_dumps(self, tasks, indentation="", result=""):
@classmethod
def print_unimplemented(cls, command):
"""Show warning that method is not yet implemented."""
print("command '%s' not implemented yet" % command, file=sys.stderr)
print(f"command '{command}' not implemented yet", file=sys.stderr)

@classmethod
def get_parser(cls):
Expand Down Expand Up @@ -222,15 +251,22 @@ def get_parser(cls):
# help="anonymize output", dest="anonymize")

parser.add_argument(
"-p", "--filter-project", dest="filter_project", help="Filter by project"
"-p", "--filter-project", dest="filter_project", help="filter by project"
)
parser.add_argument(
"-a", "--filter-area", dest="filter_area", help="Filter by area"
"-a", "--filter-area", dest="filter_area", help="filter by area"
)
parser.add_argument(
"-t", "--filtertag", dest="filter_tag", help="Filter by tag"
"-t", "--filtertag", dest="filter_tag", help="filter by tag"
)
parser.add_argument(
"-e",
"--only-projects",
action="store_true",
default=False,
dest="only_projects",
help="export only projects",
)

parser.add_argument(
"-o",
"--opml",
Expand Down Expand Up @@ -275,7 +311,7 @@ def get_parser(cls):
"--version",
"-v",
action="version",
version="%(prog)s (version {version})".format(version=__version__),
version=f"%(prog)s (version {__version__})",
)

argcomplete.autocomplete(parser)
Expand Down Expand Up @@ -306,6 +342,7 @@ def main(self, args=None):
self.filter_project = args.filter_project or None
self.filter_area = args.filter_area or None
self.filter_tag = args.filter_tag or None
self.only_projects = args.only_projects or None
self.recursive = args.recursive
# self.anonymize = args.anonymize
# self.things3.anonymize = self.anonymize ## not implemented
Expand Down