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
16 changes: 8 additions & 8 deletions lib/commands/people.sh
Original file line number Diff line number Diff line change
Expand Up @@ -224,19 +224,19 @@ _people_remove() {


# Resolve assignee to person ID
# Accepts: "me" or numeric ID
# Accepts: "me", name, email, or numeric ID
# Returns: numeric ID or empty string on error
# Note: Uses names.sh resolve_person_id for name/email resolution
resolve_assignee() {
local assignee="$1"

if [[ "$assignee" == "me" ]]; then
local profile
profile=$(api_get "/my/profile.json")
echo "$profile" | jq -r '.id'
elif [[ "$assignee" =~ ^[0-9]+$ ]]; then
echo "$assignee"
# Use resolve_person_id which handles "me", names, emails, and numeric IDs
local resolved
resolved=$(resolve_person_id "$assignee" 2>/dev/null)
if [[ -n "$resolved" ]]; then
echo "$resolved"
else
# Invalid format - return empty to signal error
# Return empty to signal error (caller handles error message)
echo ""
fi
}
99 changes: 22 additions & 77 deletions lib/commands/todolists.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,8 @@ _todolists_list() {
esac
done

if [[ -z "$project" ]]; then
project=$(get_project_id)
fi

if [[ -z "$project" ]]; then
die "No project specified. Use --in <project>" $EXIT_USAGE
fi
# Resolve project (supports names, IDs, and config fallback)
project=$(require_project_id "${project:-}")

# Get todoset from project dock
local project_data todoset_id
Expand Down Expand Up @@ -135,13 +130,8 @@ _todolists_show() {
die "Todolist ID required" $EXIT_USAGE "Usage: bcq todolists show <id>"
fi

if [[ -z "$project" ]]; then
project=$(get_project_id)
fi

if [[ -z "$project" ]]; then
die "No project specified" $EXIT_USAGE
fi
# Resolve project (supports names, IDs, and config fallback)
project=$(require_project_id "${project:-}")

local response
response=$(api_get "/buckets/$project/todolists/$todolist_id.json")
Expand Down Expand Up @@ -220,13 +210,8 @@ _todolists_create() {
die "Todolist name required" $EXIT_USAGE "Usage: bcq todolists create \"name\" --in <project>"
fi

if [[ -z "$project" ]]; then
project=$(get_project_id)
fi

if [[ -z "$project" ]]; then
die "No project specified" $EXIT_USAGE "Use --in <project>"
fi
# Resolve project (supports names, IDs, and config fallback)
project=$(require_project_id "${project:-}")

# Get todoset from project dock
local project_data todoset_id
Expand Down Expand Up @@ -298,13 +283,8 @@ _todolists_update() {
die "Name or description required" $EXIT_USAGE "Use --name and/or --description"
fi

if [[ -z "$project" ]]; then
project=$(get_project_id)
fi

if [[ -z "$project" ]]; then
die "No project specified" $EXIT_USAGE "Use --in <project>"
fi
# Resolve project (supports names, IDs, and config fallback)
project=$(require_project_id "${project:-}")

local payload="{}"
[[ -n "$name" ]] && payload=$(echo "$payload" | jq --arg n "$name" '. + {name: $n}')
Expand Down Expand Up @@ -430,21 +410,11 @@ _todolistgroups_list() {
esac
done

if [[ -z "$project" ]]; then
project=$(get_project_id)
fi
# Resolve project (supports names, IDs, and config fallback)
project=$(require_project_id "${project:-}")

if [[ -z "$project" ]]; then
die "No project specified. Use --in <project>" $EXIT_USAGE
fi

if [[ -z "$todolist_id" ]]; then
todolist_id=$(get_todolist_id)
fi

if [[ -z "$todolist_id" ]]; then
die "No todolist specified. Use --list <todolist_id>" $EXIT_USAGE
fi
# Resolve todolist (supports names, IDs, and config fallback)
todolist_id=$(require_todolist_id "${todolist_id:-}" "$project")

# GET /buckets/:project/todolists/:todolist_id/groups.json
local response
Expand Down Expand Up @@ -510,13 +480,8 @@ _todolistgroups_show() {
die "Group ID required" $EXIT_USAGE "Usage: bcq todolistgroups show <id> --in <project>"
fi

if [[ -z "$project" ]]; then
project=$(get_project_id)
fi

if [[ -z "$project" ]]; then
die "No project specified" $EXIT_USAGE "Use --in <project>"
fi
# Resolve project (supports names, IDs, and config fallback)
project=$(require_project_id "${project:-}")

# Groups are todolists: GET /buckets/:project/todolists/:group_id.json
local response
Expand Down Expand Up @@ -567,21 +532,11 @@ _todolistgroups_create() {
die "Group name required" $EXIT_USAGE "Usage: bcq todolistgroups create \"name\" --list <todolist_id> --in <project>"
fi

if [[ -z "$project" ]]; then
project=$(get_project_id)
fi

if [[ -z "$project" ]]; then
die "No project specified" $EXIT_USAGE "Use --in <project>"
fi

if [[ -z "$todolist_id" ]]; then
todolist_id=$(get_todolist_id)
fi
# Resolve project (supports names, IDs, and config fallback)
project=$(require_project_id "${project:-}")

if [[ -z "$todolist_id" ]]; then
die "No todolist specified. Use --list <todolist_id>" $EXIT_USAGE
fi
# Resolve todolist (supports names, IDs, and config fallback)
todolist_id=$(require_todolist_id "${todolist_id:-}" "$project")

local payload
payload=$(jq -n --arg name "$name" '{name: $name}')
Expand Down Expand Up @@ -636,13 +591,8 @@ _todolistgroups_update() {
die "Name required" $EXIT_USAGE "Use --name \"new name\""
fi

if [[ -z "$project" ]]; then
project=$(get_project_id)
fi

if [[ -z "$project" ]]; then
die "No project specified" $EXIT_USAGE "Use --in <project>"
fi
# Resolve project (supports names, IDs, and config fallback)
project=$(require_project_id "${project:-}")

local payload
payload=$(jq -n --arg name "$name" '{name: $name}')
Expand Down Expand Up @@ -694,13 +644,8 @@ _todolistgroups_position() {
die "Position required" $EXIT_USAGE "Use --to <position> (1 = top)"
fi

if [[ -z "$project" ]]; then
project=$(get_project_id)
fi

if [[ -z "$project" ]]; then
die "No project specified" $EXIT_USAGE "Use --in <project>"
fi
# Resolve project (supports names, IDs, and config fallback)
project=$(require_project_id "${project:-}")

local payload
payload=$(jq -n --argjson pos "$position" '{position: $pos}')
Expand Down
85 changes: 31 additions & 54 deletions lib/commands/todos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,15 @@ _todos_list() {
esac
done

# Use project from context if not specified
if [[ -z "$project" ]]; then
project=$(get_project_id)
fi

if [[ -z "$project" ]]; then
die "No project specified. Use --in <project> or set in .basecamp/config.json" $EXIT_USAGE
fi
# Resolve project (supports names, IDs, and config fallback)
project=$(require_project_id "${project:-}")

# Build path based on context
local path
if [[ -n "$todolist" ]]; then
# Resolve todolist name to ID if needed
todolist=$(resolve_todolist_id "$todolist" "$project") || \
die "$(format_resolve_error todolist "$todolist")" $EXIT_NOT_FOUND
path="/buckets/$project/todolists/$todolist/todos.json"
else
# Get todoset ID from project dock
Expand Down Expand Up @@ -189,15 +186,14 @@ _todos_list_md() {

_todos_show() {
local todo_id="$1"
local project="${2:-$(get_project_id)}"
local project="${2:-}"

if [[ -z "$todo_id" ]]; then
die "Todo ID required" $EXIT_USAGE "Usage: bcq todos show <id>"
fi

if [[ -z "$project" ]]; then
die "No project specified" $EXIT_USAGE "Use --project or set in .basecamp/config.json"
fi
# Resolve project (supports names, IDs, and config fallback)
project=$(require_project_id "${project:-}")

local response
response=$(api_get "/buckets/$project/todos/$todo_id.json")
Expand Down Expand Up @@ -287,18 +283,20 @@ cmd_todo_create() {
die "Todo content required" $EXIT_USAGE "Usage: bcq todo \"content\" [options]"
fi

# Get project from context if not specified
if [[ -z "$project" ]]; then
project=$(get_project_id)
fi

if [[ -z "$project" ]]; then
die "No project specified. Use --in <project> or set in .basecamp/config.json" $EXIT_USAGE
fi
# Resolve project (supports names, IDs, and config fallback)
project=$(require_project_id "${project:-}")

# Get todolist from context if not specified
if [[ -z "$todolist" ]]; then
# Resolve todolist (supports names, IDs, and config fallback)
if [[ -n "$todolist" ]]; then
todolist=$(resolve_todolist_id "$todolist" "$project") || \
die "$(format_resolve_error todolist "$todolist")" $EXIT_NOT_FOUND
else
todolist=$(get_config "todolist_id")
if [[ -n "$todolist" ]]; then
# Resolve config value in case it's a name
todolist=$(resolve_todolist_id "$todolist" "$project") || \
die "$(format_resolve_error todolist "$todolist")" $EXIT_NOT_FOUND
fi
fi

if [[ -z "$todolist" ]]; then
Expand All @@ -312,7 +310,7 @@ cmd_todo_create() {
fi

if [[ -z "$todolist" ]]; then
die "No todolist found. Use --list <id>" $EXIT_USAGE
die "No todolist found. Use --list <todolist>" $EXIT_USAGE
fi

# Build payload
Expand Down Expand Up @@ -375,13 +373,8 @@ cmd_todo_complete() {
die "Todo ID(s) required" $EXIT_USAGE "Usage: bcq done <id> [id...] --in <project>"
fi

if [[ -z "$project" ]]; then
project=$(get_project_id)
fi

if [[ -z "$project" ]]; then
die "No project specified" $EXIT_USAGE "Use --in <project> or set in .basecamp/config.json"
fi
# Resolve project (supports names, IDs, and config fallback)
project=$(require_project_id "${project:-}")

local completed=()
local failed=()
Expand Down Expand Up @@ -445,13 +438,8 @@ cmd_todo_uncomplete() {
die "Todo ID(s) required" $EXIT_USAGE "Usage: bcq reopen <id> [id...]"
fi

if [[ -z "$project" ]]; then
project=$(get_project_id)
fi

if [[ -z "$project" ]]; then
die "No project specified" $EXIT_USAGE "Use --project or set in .basecamp/config.json"
fi
# Resolve project (supports names, IDs, and config fallback)
project=$(require_project_id "${project:-}")

local reopened=()
local failed=()
Expand Down Expand Up @@ -547,13 +535,8 @@ _todos_sweep() {
"Use --comment and/or --complete"
fi

if [[ -z "$project" ]]; then
project=$(get_project_id)
fi

if [[ -z "$project" ]]; then
die "No project specified" $EXIT_USAGE "Use --in <project>"
fi
# Resolve project (supports names, IDs, and config fallback)
project=$(require_project_id "${project:-}")

# Build list args
local list_args=(--in "$project")
Expand Down Expand Up @@ -673,9 +656,8 @@ _todos_list_json() {
esac
done

if [[ -z "$project" ]]; then
project=$(get_project_id)
fi
# Resolve project (supports names, IDs, and config fallback)
project=$(require_project_id "${project:-}")

# Get todoset ID from project dock
local project_data todoset
Expand Down Expand Up @@ -806,13 +788,8 @@ _todos_position() {
die "Position required" $EXIT_USAGE "Use --to <position> (1 = top)"
fi

if [[ -z "$project" ]]; then
project=$(get_project_id)
fi

if [[ -z "$project" ]]; then
die "No project specified" $EXIT_USAGE "Use --project or set in .basecamp/config.json"
fi
# Resolve project (supports names, IDs, and config fallback)
project=$(require_project_id "${project:-}")

local payload
payload=$(jq -n --argjson pos "$position" '{position: $pos}')
Expand Down
Loading