lincli 2026.4.0

Linear CLI — manage issues, projects, cycles, and more from the terminal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
use clap::{Args, Subcommand};
use serde_json::json;

use crate::client::LinearClient;

#[derive(Args, Debug)]
pub struct ProjectsArgs {
    #[command(subcommand)]
    pub command: ProjectsCommand,
}

#[derive(Subcommand, Debug)]
pub enum ProjectsCommand {
    /// Get project details
    Get {
        /// Project name
        name: String,
    },
    /// List projects
    List {
        /// Filter by status
        #[arg(long)]
        status: Option<String>,
        /// Filter by team key
        #[arg(long)]
        team: Option<String>,
        /// Max results
        #[arg(long, default_value = "50")]
        limit: i32,
    },
    /// List issues in a project
    Issues {
        /// Project name
        name: String,
        /// Filter by status
        #[arg(long)]
        status: Option<String>,
        /// Max results
        #[arg(long, default_value = "50")]
        limit: i32,
    },
    /// Create a project
    Create {
        /// Project name
        #[arg(long)]
        name: String,
        /// Team key or name
        #[arg(long)]
        team: String,
        /// Description
        #[arg(long)]
        description: Option<String>,
        /// Lead (user name)
        #[arg(long)]
        lead: Option<String>,
        /// Start date (YYYY-MM-DD)
        #[arg(long)]
        start_date: Option<String>,
        /// Target date (YYYY-MM-DD)
        #[arg(long)]
        target_date: Option<String>,
    },
    /// Update a project
    Update {
        /// Project name
        name: String,
        /// New status
        #[arg(long)]
        status: Option<String>,
        /// New lead
        #[arg(long)]
        lead: Option<String>,
        /// New description
        #[arg(long)]
        description: Option<String>,
        /// New start date
        #[arg(long)]
        start_date: Option<String>,
        /// New target date
        #[arg(long)]
        target_date: Option<String>,
    },
    /// Search projects by name or keyword
    Search {
        /// Search query
        query: String,
        /// Max results
        #[arg(long, default_value = "25")]
        limit: i32,
    },
    /// Archive a project
    Archive {
        /// Project name
        name: String,
    },
    /// Unarchive a project
    Unarchive {
        /// Project name
        name: String,
    },
    /// Delete a project
    Delete {
        /// Project name
        name: String,
    },
}

pub async fn execute(args: &ProjectsArgs, json: bool, debug: bool) -> anyhow::Result<()> {
    let client = LinearClient::new(None, debug)?;

    match &args.command {
        ProjectsCommand::Get { name } => {
            let project_id = client.get_project_id(name).await?;
            let query = r#"
                query($id: String!) {
                    project(id: $id) {
                        id name description state
                        lead { id displayName }
                        startDate targetDate
                        teams { nodes { id key name } }
                        members { nodes { id displayName } }
                        issues { nodes { id } }
                        projectUpdates(first: 5) {
                            nodes {
                                id body health createdAt
                                user { displayName }
                            }
                        }
                        createdAt updatedAt
                    }
                }
            "#;
            let variables = json!({ "id": project_id });
            let result = client.query_raw(query, Some(variables)).await?;

            if json {
                crate::output::print_json(&result);
            } else {
                let project = result
                    .pointer("/data/project")
                    .ok_or_else(|| anyhow::anyhow!("Project not found: {name}"))?;

                let pname = project.get("name").and_then(|v| v.as_str()).unwrap_or("?");
                println!("\n  {}", crate::output::color::bold(pname));
                println!();

                if let Some(desc) = project.get("description").and_then(|v| v.as_str()) {
                    if !desc.is_empty() {
                        crate::output::detail::print_detail("Description", desc, 0);
                    }
                }
                if let Some(state) = project.get("state").and_then(|v| v.as_str()) {
                    crate::output::detail::print_detail("Status", state, 0);
                }
                let lead = crate::output::detail::format_user(project.get("lead"));
                crate::output::detail::print_detail("Lead", &lead, 0);

                if let Some(start) = project.get("startDate").and_then(|v| v.as_str()) {
                    crate::output::detail::print_detail("Start Date", start, 0);
                }
                if let Some(target) = project.get("targetDate").and_then(|v| v.as_str()) {
                    crate::output::detail::print_detail("Target Date", target, 0);
                }

                if let Some(teams) = project.pointer("/teams/nodes").and_then(|v| v.as_array()) {
                    let names: Vec<&str> = teams
                        .iter()
                        .filter_map(|t| t.get("key").and_then(|v| v.as_str()))
                        .collect();
                    if !names.is_empty() {
                        crate::output::detail::print_detail("Teams", &names.join(", "), 0);
                    }
                }

                if let Some(members) = project.pointer("/members/nodes").and_then(|v| v.as_array())
                {
                    crate::output::detail::print_detail(
                        "Members",
                        &format!("{}", members.len()),
                        0,
                    );
                }

                if let Some(issues) = project.pointer("/issues/nodes").and_then(|v| v.as_array()) {
                    crate::output::detail::print_detail("Issues", &format!("{}", issues.len()), 0);
                }

                if let Some(updates) = project
                    .pointer("/projectUpdates/nodes")
                    .and_then(|v| v.as_array())
                {
                    if !updates.is_empty() {
                        crate::output::detail::print_section("Recent Updates");
                        for update in updates.iter().take(3) {
                            let health =
                                update.get("health").and_then(|v| v.as_str()).unwrap_or("?");
                            let user = update
                                .pointer("/user/displayName")
                                .and_then(|v| v.as_str())
                                .unwrap_or("?");
                            let date = update
                                .get("createdAt")
                                .and_then(|v| v.as_str())
                                .unwrap_or("");
                            let body = update.get("body").and_then(|v| v.as_str()).unwrap_or("");
                            println!(
                                "    {} {} {}",
                                crate::output::detail::format_health(health),
                                crate::output::color::bold(user),
                                crate::output::color::dim(date),
                            );
                            for line in body.lines().take(3) {
                                println!("      {line}");
                            }
                            println!();
                        }
                    }
                }
            }
        }

        ProjectsCommand::List {
            status,
            team,
            limit,
        } => {
            let query = r#"
                query($filter: ProjectFilter, $first: Int!) {
                    projects(filter: $filter, first: $first) {
                        nodes {
                            id name state
                            lead { displayName }
                            startDate targetDate
                        }
                    }
                }
            "#;

            let mut filter = json!({});
            if let Some(s) = status {
                filter["state"] = json!({ "eq": s });
            }
            if let Some(team_key) = team {
                let team_id = client.get_team_id(team_key).await?;
                filter["accessibleTeams"] = json!({ "id": { "eq": team_id } });
            }

            let variables = json!({ "filter": filter, "first": limit });
            let result = client.query_raw(query, Some(variables)).await?;

            if json {
                crate::output::print_json(&result);
            } else {
                let nodes = result
                    .pointer("/data/projects/nodes")
                    .and_then(|v| v.as_array());
                match nodes {
                    Some(projects) if !projects.is_empty() => {
                        let rows: Vec<Vec<String>> = projects
                            .iter()
                            .map(|p| {
                                vec![
                                    p.get("name")
                                        .and_then(|v| v.as_str())
                                        .unwrap_or("-")
                                        .to_string(),
                                    p.get("state")
                                        .and_then(|v| v.as_str())
                                        .unwrap_or("-")
                                        .to_string(),
                                    crate::output::detail::format_user(p.get("lead")),
                                    p.get("startDate")
                                        .and_then(|v| v.as_str())
                                        .unwrap_or("-")
                                        .to_string(),
                                    p.get("targetDate")
                                        .and_then(|v| v.as_str())
                                        .unwrap_or("-")
                                        .to_string(),
                                ]
                            })
                            .collect();
                        crate::output::table::print_table(
                            &["Name", "Status", "Lead", "Start", "Target"],
                            &rows,
                        );
                    }
                    _ => println!("  No projects found."),
                }
            }
        }

        ProjectsCommand::Issues {
            name,
            status,
            limit,
        } => {
            let project_id = client.get_project_id(name).await?;
            let query = r#"
                query($filter: IssueFilter, $first: Int!) {
                    issues(filter: $filter, first: $first, orderBy: updatedAt) {
                        nodes {
                            id identifier title
                            state { name }
                            assignee { displayName }
                            priority
                            team { key }
                        }
                    }
                }
            "#;

            let mut filter = json!({ "project": { "id": { "eq": project_id } } });
            if let Some(status_name) = status {
                filter["state"] = json!({ "name": { "eqCaseInsensitive": status_name } });
            }

            let variables = json!({ "filter": filter, "first": limit });
            let result = client.query_raw(query, Some(variables)).await?;

            if json {
                crate::output::print_json(&result);
            } else {
                let nodes = result
                    .pointer("/data/issues/nodes")
                    .and_then(|v| v.as_array());
                match nodes {
                    Some(issues) if !issues.is_empty() => {
                        for issue in issues {
                            crate::output::detail::print_issue_summary(issue);
                        }
                    }
                    _ => println!("  No issues found."),
                }
            }
        }

        ProjectsCommand::Create {
            name,
            team,
            description,
            lead,
            start_date,
            target_date,
        } => {
            let query = r#"
                mutation($input: ProjectCreateInput!) {
                    projectCreate(input: $input) {
                        success
                        project { id name state }
                    }
                }
            "#;

            let team_id = client.get_team_id(team).await?;
            let mut input = json!({
                "name": name,
                "teamIds": [team_id],
            });

            if let Some(desc) = description {
                input["description"] = json!(desc);
            }
            if let Some(lead_name) = lead {
                let user_id = client.get_user_id(lead_name).await?;
                input["leadId"] = json!(user_id);
            }
            if let Some(start) = start_date {
                input["startDate"] = json!(start);
            }
            if let Some(target) = target_date {
                input["targetDate"] = json!(target);
            }

            let variables = json!({ "input": input });
            let result = client.query_raw(query, Some(variables)).await?;

            if json {
                crate::output::print_json(&result);
            } else {
                let success = result
                    .pointer("/data/projectCreate/success")
                    .and_then(|v| v.as_bool())
                    .unwrap_or(false);
                if success {
                    println!(
                        "  {} Created project {}",
                        crate::output::color::green("OK"),
                        crate::output::color::bold(name),
                    );
                } else {
                    println!(
                        "  {} Failed to create project",
                        crate::output::color::red("ERROR")
                    );
                }
            }
        }

        ProjectsCommand::Update {
            name,
            status,
            lead,
            description,
            start_date,
            target_date,
        } => {
            let project_id = client.get_project_id(name).await?;
            let query = r#"
                mutation($id: String!, $input: ProjectUpdateInput!) {
                    projectUpdate(id: $id, input: $input) {
                        success
                        project { id name state }
                    }
                }
            "#;

            let mut input = json!({});
            if let Some(s) = status {
                input["state"] = json!(s);
            }
            if let Some(lead_name) = lead {
                let user_id = client.get_user_id(lead_name).await?;
                input["leadId"] = json!(user_id);
            }
            if let Some(desc) = description {
                input["description"] = json!(desc);
            }
            if let Some(start) = start_date {
                input["startDate"] = json!(start);
            }
            if let Some(target) = target_date {
                input["targetDate"] = json!(target);
            }

            let variables = json!({ "id": project_id, "input": input });
            let result = client.query_raw(query, Some(variables)).await?;

            if json {
                crate::output::print_json(&result);
            } else {
                let success = result
                    .pointer("/data/projectUpdate/success")
                    .and_then(|v| v.as_bool())
                    .unwrap_or(false);
                if success {
                    println!(
                        "  {} Updated project {}",
                        crate::output::color::green("OK"),
                        crate::output::color::bold(name),
                    );
                } else {
                    println!(
                        "  {} Failed to update project",
                        crate::output::color::red("ERROR")
                    );
                }
            }
        }

        ProjectsCommand::Search { query: term, limit } => {
            let query = r#"
                query($term: String!, $first: Int) {
                    searchProjects(term: $term, first: $first) {
                        nodes { id name state lead { displayName } startDate targetDate }
                    }
                }
            "#;
            let variables = json!({ "term": term, "first": limit });
            let result = client.query_raw(query, Some(variables)).await?;

            if json {
                crate::output::print_json(&result);
            } else {
                let nodes = result
                    .pointer("/data/searchProjects/nodes")
                    .and_then(|v| v.as_array());
                match nodes {
                    Some(projects) if !projects.is_empty() => {
                        let rows: Vec<Vec<String>> = projects
                            .iter()
                            .map(|p| {
                                vec![
                                    p.get("name")
                                        .and_then(|v| v.as_str())
                                        .unwrap_or("-")
                                        .to_string(),
                                    p.get("state")
                                        .and_then(|v| v.as_str())
                                        .unwrap_or("-")
                                        .to_string(),
                                    crate::output::detail::format_user(p.get("lead")),
                                    p.get("startDate")
                                        .and_then(|v| v.as_str())
                                        .unwrap_or("-")
                                        .to_string(),
                                    p.get("targetDate")
                                        .and_then(|v| v.as_str())
                                        .unwrap_or("-")
                                        .to_string(),
                                ]
                            })
                            .collect();
                        crate::output::table::print_table(
                            &["Name", "Status", "Lead", "Start", "Target"],
                            &rows,
                        );
                    }
                    _ => println!("  No projects found."),
                }
            }
        }

        ProjectsCommand::Archive { name } => {
            if crate::output::interactive::is_interactive()
                && !crate::output::interactive::confirm(&format!("Archive project {name}?"))?
            {
                println!("Cancelled.");
                return Ok(());
            }

            let project_id = client.get_project_id(name).await?;
            let query = r#"
                mutation($id: String!) {
                    projectArchive(id: $id) { success }
                }
            "#;
            let variables = json!({ "id": project_id });
            let result = client.query_raw(query, Some(variables)).await?;

            if json {
                crate::output::print_json(&result);
            } else {
                let success = result
                    .pointer("/data/projectArchive/success")
                    .and_then(|v| v.as_bool())
                    .unwrap_or(false);
                if success {
                    println!(
                        "  {} Archived project {}",
                        crate::output::color::green("OK"),
                        crate::output::color::bold(name),
                    );
                } else {
                    println!(
                        "  {} Failed to archive project",
                        crate::output::color::red("ERROR")
                    );
                }
            }
        }

        ProjectsCommand::Unarchive { name } => {
            let project_id = client.get_project_id(name).await?;
            let query = r#"
                mutation($id: String!) {
                    projectUnarchive(id: $id) { success }
                }
            "#;
            let variables = json!({ "id": project_id });
            let result = client.query_raw(query, Some(variables)).await?;

            if json {
                crate::output::print_json(&result);
            } else {
                let success = result
                    .pointer("/data/projectUnarchive/success")
                    .and_then(|v| v.as_bool())
                    .unwrap_or(false);
                if success {
                    println!(
                        "  {} Unarchived project {}",
                        crate::output::color::green("OK"),
                        crate::output::color::bold(name),
                    );
                } else {
                    println!(
                        "  {} Failed to unarchive project",
                        crate::output::color::red("ERROR")
                    );
                }
            }
        }

        ProjectsCommand::Delete { name } => {
            if crate::output::interactive::is_interactive()
                && !crate::output::interactive::confirm(&format!("Delete project {name}?"))?
            {
                println!("Cancelled.");
                return Ok(());
            }

            let project_id = client.get_project_id(name).await?;
            let query = r#"
                mutation($id: String!) {
                    projectDelete(id: $id) { success }
                }
            "#;
            let variables = json!({ "id": project_id });
            let result = client.query_raw(query, Some(variables)).await?;

            if json {
                crate::output::print_json(&result);
            } else {
                let success = result
                    .pointer("/data/projectDelete/success")
                    .and_then(|v| v.as_bool())
                    .unwrap_or(false);
                if success {
                    println!(
                        "  {} Deleted project {}",
                        crate::output::color::green("OK"),
                        crate::output::color::bold(name),
                    );
                } else {
                    println!(
                        "  {} Failed to delete project",
                        crate::output::color::red("ERROR")
                    );
                }
            }
        }
    }

    Ok(())
}