Skip to content

Commit

Permalink
Add support for item links & text writing to 'add'
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-harvey-dev authored and lbiaggi committed Jan 17, 2025
1 parent 314dac7 commit 7137b8a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
14 changes: 13 additions & 1 deletion doorstop/cli/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,14 @@ def run_add(args, cwd, _, catch=True):
request_next_number = _request_next_number(args)
tree = _get_tree(args, cwd, request_next_number=request_next_number)
document = tree.find_document(args.prefix)

try:
if args.count > 1 and (args.link or args.text):
raise AssertionError(
"Link and Text can only be parsed when creating a single Doorstop Item!",
)
except AssertionError as argsError:
log.error(argsError)
return False
# add items to it
for _ in range(args.count):
item = document.add_item(
Expand All @@ -186,6 +193,11 @@ def run_add(args, cwd, _, catch=True):
name=args.name,
reorder=args.noreorder,
)

if args.link:
item.link(args.link)
if args.text:
item.set("text", args.text)
utilities.show("added item: {} ({})".format(item.uid, item.relpath))

# Edit item if requested
Expand Down
12 changes: 12 additions & 0 deletions doorstop/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ def main(args=None): # pylint: disable=R0915

# Parse arguments
args = parser.parse_args(args=args)

# Configure logging
utilities.configure_logging(args.verbose)

Expand Down Expand Up @@ -311,6 +312,17 @@ def _add(subs, shared):
type=utilities.positive_int,
help="number of items to create",
)

sub.add_argument(
"--link",
help=("Doorstop Item to link this new Item to"),
)
sub.add_argument(
"-t",
"--text",
help=("Text to write into doorstop Item at point of creation"),
)

sub.add_argument(
"--edit",
action="store_true",
Expand Down

0 comments on commit 7137b8a

Please sign in to comment.