Skip to content

Commit 9f73bc0

Browse files
committed
feat(cli): Add code-mappings upload command scaffold with file parsing
Add a new `code-mappings` subcommand group with an `upload` subcommand that reads and validates a JSON file of code mappings. This is the first step toward CLI support for bulk code mapping uploads to Sentry.
1 parent d893c9d commit 9f73bc0

File tree

4 files changed

+8
-15
lines changed

4 files changed

+8
-15
lines changed

src/commands/code_mappings/upload.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use std::fs;
22

33
use anyhow::{bail, Context as _, Result};
44
use clap::{Arg, ArgMatches, Command};
5-
use serde::Deserialize;
5+
use serde::{Deserialize, Serialize};
66

7-
#[derive(Debug, Deserialize)]
7+
#[derive(Debug, Deserialize, Serialize)]
88
#[serde(rename_all = "camelCase")]
99
struct CodeMapping {
1010
stack_root: String,
@@ -13,7 +13,7 @@ struct CodeMapping {
1313

1414
pub fn make_command(command: Command) -> Command {
1515
command
16-
.about("Upload code mappings for a project from a JSON file. Each mapping pairs a stack trace root (e.g. com/example/module) with the corresponding source path in your repository (e.g. modules/module/src/main/java/com/example/module).")
16+
.about("Upload code mappings for a project from a JSON file.")
1717
.arg(
1818
Arg::new("path")
1919
.value_name("PATH")
@@ -36,9 +36,8 @@ pub fn make_command(command: Command) -> Command {
3636
}
3737

3838
pub fn execute(matches: &ArgMatches) -> Result<()> {
39-
let path = matches
40-
.get_one::<String>("path")
41-
.expect("path is a required argument");
39+
#[expect(clippy::unwrap_used, reason = "path is a required argument")]
40+
let path = matches.get_one::<String>("path").unwrap();
4241
let data = fs::read(path).with_context(|| format!("Failed to read mappings file '{path}'"))?;
4342

4443
let mappings: Vec<CodeMapping> =

tests/integration/_cases/code_mappings/code-mappings-help.trycmd

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ repository, enabling source context and code linking in Sentry.
77
Usage: sentry-cli[EXE] code-mappings [OPTIONS] <COMMAND>
88

99
Commands:
10-
upload Upload code mappings for a project from a JSON file. Each mapping pairs a stack trace root
11-
(e.g. com/example/module) with the corresponding source path in your repository (e.g.
12-
modules/module/src/main/java/com/example/module).
10+
upload Upload code mappings for a project from a JSON file.
1311
help Print this message or the help of the given subcommand(s)
1412

1513
Options:

tests/integration/_cases/code_mappings/code-mappings-no-subcommand.trycmd

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ repository, enabling source context and code linking in Sentry.
77
Usage: sentry-cli[EXE] code-mappings [OPTIONS] <COMMAND>
88

99
Commands:
10-
upload Upload code mappings for a project from a JSON file. Each mapping pairs a stack trace root
11-
(e.g. com/example/module) with the corresponding source path in your repository (e.g.
12-
modules/module/src/main/java/com/example/module).
10+
upload Upload code mappings for a project from a JSON file.
1311
help Print this message or the help of the given subcommand(s)
1412

1513
Options:

tests/integration/_cases/code_mappings/code-mappings-upload-help.trycmd

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
```
22
$ sentry-cli code-mappings upload --help
33
? success
4-
Upload code mappings for a project from a JSON file. Each mapping pairs a stack trace root (e.g.
5-
com/example/module) with the corresponding source path in your repository (e.g.
6-
modules/module/src/main/java/com/example/module).
4+
Upload code mappings for a project from a JSON file.
75

86
Usage: sentry-cli[EXE] code-mappings upload [OPTIONS] <PATH>
97

0 commit comments

Comments
 (0)