-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod.rs
More file actions
205 lines (186 loc) · 5.83 KB
/
Copy pathmod.rs
File metadata and controls
205 lines (186 loc) · 5.83 KB
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
//! CLI argument parsing types.
//!
//! This module provides the command-line interface structure for the fossapi binary.
use clap::{Parser, Subcommand, ValueEnum};
/// FOSSA API command-line interface.
#[derive(Parser, Debug)]
#[command(name = "fossapi", about = "FOSSA API CLI", version)]
pub struct Cli {
/// Output results as JSON instead of a table.
#[arg(long, global = true, default_value = "false")]
pub json: bool,
#[command(subcommand)]
pub command: Command,
}
/// Available CLI commands.
#[derive(Subcommand, Debug)]
pub enum Command {
/// Get a single entity by locator or ID.
Get {
#[command(subcommand)]
command: GetCommand,
},
/// List entities with optional filtering and pagination.
List {
#[command(subcommand)]
command: ListCommand,
},
/// Update an entity.
Update {
/// The type of entity to update.
entity: Entity,
/// The locator of the entity to update.
locator: String,
/// New title for the entity.
#[arg(long)]
title: Option<String>,
/// New description for the entity.
#[arg(long)]
description: Option<String>,
/// Set project visibility (true = public, false = private).
#[arg(long)]
public: Option<bool>,
},
/// Run the MCP server on stdio.
Mcp {
/// Enable verbose (debug) logging.
#[arg(long)]
verbose: bool,
},
}
/// Subcommands for the `get` command with type-safe ID parsing.
#[derive(Subcommand, Debug, Clone, PartialEq, Eq)]
pub enum GetCommand {
/// Get a project by locator.
#[command(alias = "projects")]
Project {
/// The project locator (e.g., "custom+org/repo").
locator: String,
},
/// Get a revision by locator.
#[command(alias = "revisions")]
Revision {
/// The revision locator (e.g., "custom+org/repo$ref").
locator: String,
},
/// Get an issue by numeric ID.
#[command(alias = "issues")]
Issue {
/// The issue ID.
id: u64,
},
#[command(
about = "Get a snippet's details, including its matched first-party files",
alias = "snippets"
)]
Snippet {
#[arg(help = "The revision locator (e.g. custom+org/repo$ref)")]
revision: String,
#[arg(help = "The snippet ID")]
snippet: String,
},
#[command(about = "Show the side-by-side match details for a snippet at a first-party path")]
SnippetMatch {
#[arg(help = "The revision locator (e.g. custom+org/repo$ref)")]
revision: String,
#[arg(help = "The snippet ID")]
snippet: String,
#[arg(help = "The first-party file path where the snippet matched")]
path: String,
},
}
/// Subcommands for the `list` command with type-safe argument parsing.
#[derive(Subcommand, Debug, Clone, PartialEq, Eq)]
pub enum ListCommand {
/// List all projects.
#[command(alias = "project")]
Projects {
/// Page number (1-indexed).
#[arg(long)]
page: Option<u32>,
/// Number of items per page.
#[arg(long)]
count: Option<u32>,
},
/// List all issues.
#[command(alias = "issue")]
Issues {
/// Page number (1-indexed).
#[arg(long)]
page: Option<u32>,
/// Number of items per page.
#[arg(long)]
count: Option<u32>,
},
/// List dependencies for a revision.
#[command(alias = "dependency")]
Dependencies {
/// The revision locator (e.g., "custom+org/repo$ref").
#[arg(long, required_unless_present = "revision_positional")]
revision: Option<String>,
/// The revision locator (positional, alternative to --revision).
#[arg(index = 1, required_unless_present = "revision")]
revision_positional: Option<String>,
},
/// List revisions for a project.
#[command(alias = "revision")]
Revisions {
/// The project locator (e.g., "custom+org/repo").
project: String,
/// Page number (1-indexed).
#[arg(long)]
page: Option<u32>,
/// Number of items per page.
#[arg(long)]
count: Option<u32>,
},
#[command(
about = "List snippets (matched OSS packages) in a revision",
alias = "snippet"
)]
Snippets {
#[arg(help = "The revision locator (e.g. custom+org/repo$ref)")]
revision: String,
#[arg(long, help = "Filter by file/directory path (defaults to /)")]
path: Option<String>,
#[arg(long)]
page: Option<u32>,
#[arg(long)]
count: Option<u32>,
},
#[command(about = "List every snippet match location (first-party file -> matched package)")]
SnippetLocations {
#[arg(help = "The revision locator (e.g. custom+org/repo$ref)")]
revision: String,
#[arg(long, help = "Filter by file/directory path (defaults to /)")]
path: Option<String>,
#[arg(
long,
help = "Resolve the first-party line range for each match (extra API calls)"
)]
with_lines: bool,
},
#[command(about = "List the file/directory tree where snippets were detected")]
SnippetPaths {
#[arg(help = "The revision locator (e.g. custom+org/repo$ref)")]
revision: String,
#[arg(long, help = "File/directory path to drill into (defaults to /)")]
path: Option<String>,
},
}
/// Entity types that can be operated on.
#[derive(ValueEnum, Clone, Debug, PartialEq, Eq)]
pub enum Entity {
/// A FOSSA project.
#[value(alias = "projects")]
Project,
/// A project revision.
#[value(alias = "revisions")]
Revision,
/// A package dependency.
#[value(alias = "dependencies")]
Dependency,
/// A security/licensing/quality issue.
#[value(alias = "issues")]
Issue,
}