sharepoint-cli-rs 0.1.0__tar.gz → 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/CHANGELOG.md +9 -0
  2. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/Cargo.lock +1 -1
  3. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/Cargo.toml +1 -1
  4. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/PKG-INFO +12 -5
  5. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/README.md +11 -4
  6. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/examples/simulator/server.rs +6 -3
  7. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/examples/simulator/smoke.rs +43 -7
  8. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/src/backend.rs +3 -2
  9. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/src/cli.rs +1 -1
  10. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/src/commands/files.rs +20 -14
  11. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/src/commands/schema.rs +5 -5
  12. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/src/commands/sites.rs +3 -2
  13. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/src/graph/drives.rs +4 -0
  14. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/src/graph/search.rs +47 -12
  15. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/src/main.rs +27 -8
  16. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/src/pagination.rs +10 -0
  17. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/src/reference.rs +1 -1
  18. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/src/rest/drives.rs +3 -1
  19. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/src/rest/search.rs +26 -8
  20. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/tests/cmd_clap_error_is_json.rs +36 -0
  21. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/tests/cmd_files_find.rs +104 -0
  22. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/tests/cmd_files_ls_pagination.rs +6 -1
  23. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/tests/cmd_rest_files_find.rs +101 -3
  24. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/tests/cmd_rest_files_ls.rs +5 -2
  25. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/tests/cmd_sites_list.rs +41 -0
  26. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/.envrc +0 -0
  27. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/.github/workflows/ci.yml +0 -0
  28. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/.github/workflows/clispec.yml +0 -0
  29. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/.github/workflows/dependencies.yml +0 -0
  30. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/.github/workflows/release.yml +0 -0
  31. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/.gitignore +0 -0
  32. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/.mise.toml +0 -0
  33. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/Makefile +0 -0
  34. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/docs/releases.md +0 -0
  35. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/docs/superpowers/.gitignore +0 -0
  36. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/docs/testing.md +0 -0
  37. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/examples/simulator/contracts/LICENSE.pnpcore +0 -0
  38. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/examples/simulator/contracts/README.md +0 -0
  39. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/examples/simulator/contracts/pnpcore.json +0 -0
  40. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/examples/simulator/contracts/provenance.json +0 -0
  41. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/examples/simulator/fixtures.json +0 -0
  42. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/examples/simulator/main.rs +0 -0
  43. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/examples/simulator/odata.rs +0 -0
  44. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/examples/simulator/recording.rs +0 -0
  45. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/flake.lock +0 -0
  46. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/flake.nix +0 -0
  47. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/nix/overlay-check.nix +0 -0
  48. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/nix/package.nix +0 -0
  49. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/prek.toml +0 -0
  50. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/pyproject.toml +0 -0
  51. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/scripts/import_pnpcore_contracts.py +0 -0
  52. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/sharepoint_cli/__init__.py +0 -0
  53. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/sharepoint_cli/__main__.py +0 -0
  54. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/sharepoint_cli/py.typed +0 -0
  55. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/src/auth/browser.rs +0 -0
  56. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/src/auth/device_code.rs +0 -0
  57. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/src/auth/mod.rs +0 -0
  58. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/src/auth/session_store.rs +0 -0
  59. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/src/auth/token_cache.rs +0 -0
  60. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/src/commands/auth.rs +0 -0
  61. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/src/commands/config.rs +0 -0
  62. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/src/commands/doctor.rs +0 -0
  63. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/src/commands/drives.rs +0 -0
  64. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/src/commands/init.rs +0 -0
  65. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/src/commands/mod.rs +0 -0
  66. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/src/commands/profile.rs +0 -0
  67. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/src/config.rs +0 -0
  68. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/src/error.rs +0 -0
  69. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/src/graph/download.rs +0 -0
  70. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/src/graph/mod.rs +0 -0
  71. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/src/graph/sites.rs +0 -0
  72. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/src/lib.rs +0 -0
  73. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/src/output.rs +0 -0
  74. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/src/rest/download.rs +0 -0
  75. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/src/rest/mod.rs +0 -0
  76. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/src/rest/sites.rs +0 -0
  77. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/src/util.rs +0 -0
  78. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/tests/auth_concurrent_refresh.rs +0 -0
  79. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/tests/auth_refresh.rs +0 -0
  80. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/tests/auth_token_retry.rs +0 -0
  81. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/tests/cmd_auth_env_refresh_token.rs +0 -0
  82. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/tests/cmd_auth_login_canonicalizes_tenant.rs +0 -0
  83. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/tests/cmd_auth_login_quiet_prompts.rs +0 -0
  84. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/tests/cmd_auth_logout.rs +0 -0
  85. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/tests/cmd_auth_no_client_id.rs +0 -0
  86. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/tests/cmd_auth_status.rs +0 -0
  87. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/tests/cmd_backend_contract.rs +0 -0
  88. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/tests/cmd_collection_pagination.rs +0 -0
  89. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/tests/cmd_config.rs +0 -0
  90. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/tests/cmd_download_safety.rs +0 -0
  91. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/tests/cmd_drives_list.rs +0 -0
  92. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/tests/cmd_drives_list_pagination.rs +0 -0
  93. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/tests/cmd_files_ls.rs +0 -0
  94. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/tests/cmd_files_ls_recursive_rejects_pagination_flags.rs +0 -0
  95. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/tests/cmd_files_stat_download.rs +0 -0
  96. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/tests/cmd_flags.rs +0 -0
  97. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/tests/cmd_init_quiet.rs +0 -0
  98. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/tests/cmd_pagination_safety.rs +0 -0
  99. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/tests/cmd_profile.rs +0 -0
  100. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/tests/cmd_rest_auth.rs +0 -0
  101. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/tests/cmd_rest_drives_list.rs +0 -0
  102. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/tests/cmd_rest_files_stat_download.rs +0 -0
  103. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/tests/cmd_rest_sites_list.rs +0 -0
  104. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/tests/cmd_schema.rs +0 -0
  105. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/tests/cmd_sites_use.rs +0 -0
  106. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/tests/device_code_polling.rs +0 -0
  107. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/tests/fixtures/clispec-v0.3.json +0 -0
  108. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/tests/graph_download.rs +0 -0
  109. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/tests/graph_page_token_host_validation.rs +0 -0
  110. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/tests/graph_retry.rs +0 -0
  111. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/tests/rest_client.rs +0 -0
  112. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/tests/simulator.rs +0 -0
  113. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/tests/support/backend.rs +0 -0
  114. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/tests/support/mod.rs +0 -0
  115. {sharepoint_cli_rs-0.1.0 → sharepoint_cli_rs-0.1.1}/vership.toml +0 -0
@@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.
4
4
 
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/).
6
6
 
7
+ ## [0.1.1](https://github.com/rvben/sharepoint-cli/compare/v0.1.0...v0.1.1) - 2026-11-06
8
+
9
+ ### Fixed
10
+
11
+ - report total as the collection size or null, never the page size ([87c07d6](https://github.com/rvben/sharepoint-cli/commit/87c07d6ae260b0b3f292556f14aaa59368a1d7fe))
12
+ - keep reading search pages until files find reaches --limit ([0353186](https://github.com/rvben/sharepoint-cli/commit/035318691463a3c137c7afd47300a69c27926850))
13
+ - search only the referenced folder in files find ([2d50eb4](https://github.com/rvben/sharepoint-cli/commit/2d50eb45d71f84d8eb6a8d4f8c346ff46a8172e0))
14
+ - name the missing argument in command-line errors ([0ddf284](https://github.com/rvben/sharepoint-cli/commit/0ddf28476b8e1a9e43d510fd383868352025f641))
15
+
7
16
  ## [0.1.0](https://github.com/rvben/sharepoint-cli/compare/v0.0.14...v0.1.0) - 2026-11-03
8
17
 
9
18
  ### Added
@@ -1721,7 +1721,7 @@ dependencies = [
1721
1721
 
1722
1722
  [[package]]
1723
1723
  name = "sharepoint-cli"
1724
- version = "0.1.0"
1724
+ version = "0.1.1"
1725
1725
  dependencies = [
1726
1726
  "assert_cmd",
1727
1727
  "base64",
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "sharepoint-cli"
3
- version = "0.1.0"
3
+ version = "0.1.1"
4
4
  edition = "2024"
5
5
  rust-version = "1.90"
6
6
  description = "Agent-friendly SharePoint Online CLI with JSON output, structured exit codes, and schema introspection"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sharepoint-cli-rs
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Classifier: Development Status :: 3 - Alpha
5
5
  Classifier: Environment :: Console
6
6
  Classifier: Intended Audience :: System Administrators
@@ -151,12 +151,19 @@ input error instead.
151
151
 
152
152
  List responses contain `items`, `total`, and an opaque `next` cursor. Pass a
153
153
  non-null cursor back with `--page`; stop when `next` is null. `--limit` must be
154
- positive and sets an upper bound, so a server page or a search filtered by
155
- `--name` can return fewer items. Use `--all` for sites, drives, file listings,
154
+ positive and sets an upper bound; `sites list` can return fewer items when a
155
+ server page ends first. Use `--all` for sites, drives, file listings,
156
156
  and search to fetch all remaining pages. `files ls --recursive` returns the
157
157
  complete tree and cannot be combined with pagination flags.
158
- For sites and files, `total` counts the returned items. For drives and Graph
159
- cached accounts, it counts the complete collection before limiting.
158
+ `total` is the size of the complete collection, never the size of the page.
159
+ For sites and `files find` it is known only when one response holds every
160
+ item (no incoming `--page`, null `next`), and is `null` otherwise. For REST
161
+ `files ls` it is always the folder's item count; for Graph `files ls` it is
162
+ `null` while more pages remain. For drives and Graph cached accounts it counts
163
+ the complete collection before limiting.
164
+ `files find` searches the referenced folder and its subfolders; reference the
165
+ library root to search the whole library. With `--name`, it keeps reading
166
+ search pages until `--limit` matches are found or the results run out.
160
167
  Graph `auth status` supports `--limit` and `--page`; REST status describes a
161
168
  single host session and rejects `--page`.
162
169
 
@@ -130,12 +130,19 @@ input error instead.
130
130
 
131
131
  List responses contain `items`, `total`, and an opaque `next` cursor. Pass a
132
132
  non-null cursor back with `--page`; stop when `next` is null. `--limit` must be
133
- positive and sets an upper bound, so a server page or a search filtered by
134
- `--name` can return fewer items. Use `--all` for sites, drives, file listings,
133
+ positive and sets an upper bound; `sites list` can return fewer items when a
134
+ server page ends first. Use `--all` for sites, drives, file listings,
135
135
  and search to fetch all remaining pages. `files ls --recursive` returns the
136
136
  complete tree and cannot be combined with pagination flags.
137
- For sites and files, `total` counts the returned items. For drives and Graph
138
- cached accounts, it counts the complete collection before limiting.
137
+ `total` is the size of the complete collection, never the size of the page.
138
+ For sites and `files find` it is known only when one response holds every
139
+ item (no incoming `--page`, null `next`), and is `null` otherwise. For REST
140
+ `files ls` it is always the folder's item count; for Graph `files ls` it is
141
+ `null` while more pages remain. For drives and Graph cached accounts it counts
142
+ the complete collection before limiting.
143
+ `files find` searches the referenced folder and its subfolders; reference the
144
+ library root to search the whole library. With `--name`, it keeps reading
145
+ search pages until `--limit` matches are found or the results run out.
139
146
  Graph `auth status` supports `--limit` and `--page`; REST status describes a
140
147
  single host session and rejects `--page`.
141
148
 
@@ -542,10 +542,13 @@ impl Api {
542
542
  for site in &self.fixtures.sites {
543
543
  for library in &site.libraries {
544
544
  let root = library.root_path(site);
545
- if format!("https://{}{root}", site.host) != scope {
546
- continue;
547
- }
548
545
  for file in &library.files {
546
+ // KQL `path:` is a case-insensitive URL prefix match, so a
547
+ // folder scope also matches siblings sharing its prefix.
548
+ let url = format!("https://{}{root}/{}", site.host, file.path);
549
+ if !url.to_lowercase().starts_with(&scope.to_lowercase()) {
550
+ continue;
551
+ }
549
552
  if matches_text(&file.path, &text) || matches_text(&file.content, &text) {
550
553
  rows.push(cells(&[
551
554
  ("FileName", name(&file.path).into()),
@@ -109,12 +109,16 @@ fn recorded_responses(cli: &Path, endpoint: &str) -> Result<Vec<String>> {
109
109
  )?;
110
110
  checks.push("PnP recordings: folder metadata after file 404".into());
111
111
 
112
- let first = runner.json(&["files", "find", &library, "--query", "*"])?;
112
+ let first = runner.json(&["files", "find", &library, "--query", "*", "--limit", "10"])?;
113
113
  let next = cursor(&first)?;
114
- let second = runner.json(&["files", "find", &library, "--query", "*", "--page", &next])?;
114
+ let second = runner.json(&[
115
+ "files", "find", &library, "--query", "*", "--limit", "10", "--page", &next,
116
+ ])?;
115
117
  ensure(
116
- first["total"] == 10
117
- && second["total"] == 10
118
+ first["items"].as_array().map(Vec::len) == Some(10)
119
+ && second["items"].as_array().map(Vec::len) == Some(10)
120
+ && first["total"].is_null()
121
+ && second["total"].is_null()
118
122
  && first["items"][0]["path"] == "/result-01.txt"
119
123
  && second["items"][0]["path"] == "/result-11.txt"
120
124
  && second["items"][9]["path"] == "/result-20.txt"
@@ -197,10 +201,29 @@ fn happy_path(cli: &Path, endpoint: &str) -> Result<Vec<String>> {
197
201
  let first = runner.json(&["files", "ls", &library, "--limit", "2"])?;
198
202
  let next = cursor(&first)?;
199
203
  let second = runner.json(&["files", "ls", &library, "--page", &next])?;
204
+ let names = |page: &Value| -> Vec<String> {
205
+ page["items"]
206
+ .as_array()
207
+ .map(|items| {
208
+ items
209
+ .iter()
210
+ .filter_map(|i| i["name"].as_str().map(str::to_owned))
211
+ .collect()
212
+ })
213
+ .unwrap_or_default()
214
+ };
215
+ let (first_names, second_names) = (names(&first), names(&second));
200
216
  ensure(
201
- first["total"] == 2 && second["total"] == 2,
217
+ first_names.len() == 2
218
+ && second_names.len() == 2
219
+ && first_names.iter().all(|n| !second_names.contains(n))
220
+ && second["next"].is_null(),
202
221
  "folder cursor lost or duplicated items",
203
222
  )?;
223
+ ensure(
224
+ first["total"] == 4 && second["total"] == 4,
225
+ "folder total is not the folder's item count",
226
+ )?;
204
227
  let all = runner.json(&["files", "ls", &library, "--all"])?;
205
228
  ensure(
206
229
  all["total"] == 4
@@ -231,9 +254,11 @@ fn happy_path(cli: &Path, endpoint: &str) -> Result<Vec<String>> {
231
254
  )?;
232
255
  checks.push("folder listing, cursors, empty folders, and recursion".into());
233
256
 
234
- let first = runner.json(&["files", "find", &library, "--query", "txt"])?;
257
+ let first = runner.json(&["files", "find", &library, "--query", "txt", "--limit", "1"])?;
235
258
  let next = cursor(&first)?;
236
- let second = runner.json(&["files", "find", &library, "--query", "txt", "--page", &next])?;
259
+ let second = runner.json(&[
260
+ "files", "find", &library, "--query", "txt", "--limit", "1", "--page", &next,
261
+ ])?;
237
262
  ensure(
238
263
  first["items"][0]["path"] != second["items"][0]["path"],
239
264
  "search cursor repeated the first page",
@@ -247,6 +272,17 @@ fn happy_path(cli: &Path, endpoint: &str) -> Result<Vec<String>> {
247
272
  filtered["total"] == 1 && filtered["items"][0]["name"] == "O'Brien #1 %.txt",
248
273
  "quoted search query differs",
249
274
  )?;
275
+ let plans = runner.json(&[
276
+ "files",
277
+ "find",
278
+ &format!("{library}/Plans"),
279
+ "--query",
280
+ "txt",
281
+ ])?;
282
+ ensure(
283
+ plans["total"] == 1 && plans["items"][0]["path"] == "/Plans/Q4 plan.txt",
284
+ "folder search is not scoped to the folder",
285
+ )?;
250
286
  checks.push("library search, scope, and pagination".into());
251
287
 
252
288
  let file = format!("{library}/O%27Brien%20%231%20%25.txt");
@@ -136,12 +136,13 @@ impl Backend {
136
136
  pub(crate) async fn search(
137
137
  &self,
138
138
  drive: &Drive,
139
+ folder: &str,
139
140
  query: &str,
140
141
  page_url: Option<&str>,
141
142
  ) -> Result<SearchResult> {
142
143
  match self {
143
- Backend::Graph(g) => graph::search::search(g, &drive.id, query, page_url).await,
144
- Backend::Rest(r) => rest::search::search(r, drive, query, page_url).await,
144
+ Backend::Graph(g) => graph::search::search(g, &drive.id, folder, query, page_url).await,
145
+ Backend::Rest(r) => rest::search::search(r, drive, folder, query, page_url).await,
145
146
  }
146
147
  }
147
148
  }
@@ -239,7 +239,7 @@ pub enum FilesCmd {
239
239
  #[arg(long)]
240
240
  overwrite: bool,
241
241
  },
242
- /// Search inside a drive (by query and/or shell glob).
242
+ /// Search a library or folder, including subfolders (by query and/or shell glob).
243
243
  Find {
244
244
  #[arg(value_name = "REF")]
245
245
  reference: String,
@@ -189,6 +189,7 @@ async fn ls(
189
189
  };
190
190
 
191
191
  let mut items: Vec<_> = Vec::new();
192
+ let mut folder_total = None;
192
193
 
193
194
  let mut seen = std::collections::HashSet::new();
194
195
  let out_cursor = 'outer: loop {
@@ -196,6 +197,7 @@ async fn ls(
196
197
  .list_children(&r.site, &r.drive, &r.parsed.path, current_url.as_deref())
197
198
  .await?;
198
199
  crate::pagination::record_page(&mut seen, &pageres.fetched_url)?;
200
+ folder_total = folder_total.or(pageres.folder_total);
199
201
 
200
202
  for (idx, it) in pageres.items.iter().enumerate() {
201
203
  if idx < skip {
@@ -220,6 +222,11 @@ async fn ls(
220
222
  };
221
223
 
222
224
  let next_token = out_cursor.as_ref().map(encode_cursor);
225
+ let total = folder_total.or(crate::pagination::observed_total(
226
+ page.is_some(),
227
+ next_token.is_some(),
228
+ items.len(),
229
+ ));
223
230
 
224
231
  if rt.out.json {
225
232
  let json_items: Vec<_> = items
@@ -227,7 +234,7 @@ async fn ls(
227
234
  .map(|it| filter_fields(canonical_json(it, &r.site, &r.drive, false), fields))
228
235
  .collect();
229
236
  rt.out.print_json(&serde_json::json!({
230
- "total": json_items.len(),
237
+ "total": total,
231
238
  "next": next_token,
232
239
  "items": json_items,
233
240
  }));
@@ -398,7 +405,9 @@ async fn find(
398
405
 
399
406
  let mut seen = std::collections::HashSet::new();
400
407
  let out_cursor = 'outer: loop {
401
- let res = backend.search(&r.drive, q, current_url.as_deref()).await?;
408
+ let res = backend
409
+ .search(&r.drive, &r.parsed.path, q, current_url.as_deref())
410
+ .await?;
402
411
  crate::pagination::record_page(&mut seen, &res.fetched_url)?;
403
412
 
404
413
  for (idx, it) in res.items.iter().enumerate() {
@@ -423,21 +432,17 @@ async fn find(
423
432
  }
424
433
  skip = 0;
425
434
 
426
- if all {
427
- match res.next_url {
428
- Some(url) => current_url = Some(url),
429
- None => break None,
430
- }
431
- } else {
432
- break res.next_url.map(|url| crate::graph::Cursor {
433
- next: Some(url),
434
- skip: 0,
435
- });
435
+ // Keep reading until `limit` matches are collected: a page can hold
436
+ // no matches for `--name` while later pages do.
437
+ match res.next_url {
438
+ Some(url) => current_url = Some(url),
439
+ None => break None,
436
440
  }
437
441
  };
438
442
 
439
443
  let next_token = out_cursor.as_ref().map(encode_cursor);
440
- let total = items.len();
444
+ let total =
445
+ crate::pagination::observed_total(page.is_some(), next_token.is_some(), items.len());
441
446
  if rt.out.json {
442
447
  let json_items: Vec<_> = items
443
448
  .iter()
@@ -452,7 +457,8 @@ async fn find(
452
457
  for it in &items {
453
458
  rt.out.print_data(&it.name);
454
459
  }
455
- rt.out.print_message(&format!("({total} match(es))"));
460
+ rt.out
461
+ .print_message(&format!("({} match(es))", items.len()));
456
462
  }
457
463
  Ok(())
458
464
  }
@@ -230,7 +230,7 @@ pub fn run(command_filter: Option<&str>) -> crate::error::Result<()> {
230
230
  ],
231
231
  "output_fields": [
232
232
  {"name": "items", "type": "object[]"},
233
- {"name": "total", "type": "integer"},
233
+ {"name": "total", "type": "integer | null", "description": "Size of the complete result set; null when this response alone does not establish it (more pages remain, or the response resumed from --page)."},
234
234
  {"name": "next", "type": "string | null"},
235
235
  {"name": "source", "type": "string"}
236
236
  ]
@@ -293,7 +293,7 @@ pub fn run(command_filter: Option<&str>) -> crate::error::Result<()> {
293
293
  ],
294
294
  "output_fields": [
295
295
  {"name": "items", "type": "object[]"},
296
- {"name": "total", "type": "integer"},
296
+ {"name": "total", "type": "integer | null", "description": "Number of items in the folder; null when unknown (Graph backend while more pages remain, or after --page)."},
297
297
  {"name": "next", "type": "string | null"}
298
298
  ]
299
299
  },
@@ -331,10 +331,10 @@ pub fn run(command_filter: Option<&str>) -> crate::error::Result<()> {
331
331
  },
332
332
  {
333
333
  "name": "find",
334
- "description": "Search for files by query and/or name glob.",
334
+ "description": "Search for files by query and/or name glob within the referenced folder and its subfolders.",
335
335
  "mutating": false,
336
336
  "args": [
337
- {"name": "REF", "type": "string", "required": true, "description": "Drive root reference (Site:Library or spo://Site/Library)."},
337
+ {"name": "REF", "type": "string", "required": true, "description": "Library or folder to search (Site:Library/folder or spo://Site/Library/folder)."},
338
338
  {"name": "--query", "type": "string", "required": false, "description": "Full-text search query."},
339
339
  {"name": "--name", "type": "string", "required": false, "description": "Shell glob to filter results by file name."},
340
340
  {"name": "--limit", "type": "integer", "required": false, "default": 200, "description": "Maximum number of results."},
@@ -344,7 +344,7 @@ pub fn run(command_filter: Option<&str>) -> crate::error::Result<()> {
344
344
  ],
345
345
  "output_fields": [
346
346
  {"name": "items", "type": "object[]"},
347
- {"name": "total", "type": "integer"},
347
+ {"name": "total", "type": "integer | null", "description": "Number of matches in the complete result set; null when this response alone does not establish it (more pages remain, or the response resumed from --page)."},
348
348
  {"name": "next", "type": "string | null"}
349
349
  ]
350
350
  }
@@ -75,7 +75,8 @@ async fn list(
75
75
  };
76
76
 
77
77
  let next_token = out_cursor.as_ref().map(encode_cursor);
78
- let total = items.len();
78
+ let total =
79
+ crate::pagination::observed_total(page.is_some(), next_token.is_some(), items.len());
79
80
  if rt.out.json {
80
81
  let json_items: Vec<_> = items
81
82
  .iter()
@@ -102,7 +103,7 @@ async fn list(
102
103
  .print_data(&format!("{:40} {}", s.display_name, s.web_url));
103
104
  }
104
105
  rt.out
105
- .print_message(&format!("({total} site(s), source={source_label})"));
106
+ .print_message(&format!("({} site(s), source={source_label})", items.len()));
106
107
  }
107
108
  Ok(())
108
109
  }
@@ -121,6 +121,9 @@ pub(crate) struct ListChildrenResult {
121
121
  /// The URL that was actually fetched (the `page_url` argument resolved to a
122
122
  /// full URL). Used by callers that need to encode a mid-page cursor.
123
123
  pub(crate) fetched_url: String,
124
+ /// Number of children in the whole folder, when the backend knows it
125
+ /// regardless of paging.
126
+ pub(crate) folder_total: Option<usize>,
124
127
  }
125
128
 
126
129
  /// Fetch one page of children. `page_url` is the full Graph URL to fetch;
@@ -151,6 +154,7 @@ pub(crate) async fn list_children(
151
154
  items: page.value,
152
155
  next_url: page.next_link,
153
156
  fetched_url: absolute_url,
157
+ folder_total: None,
154
158
  })
155
159
  }
156
160
 
@@ -3,9 +3,10 @@
3
3
  //! The `find` command uses this and adds client-side glob filtering on top
4
4
  //! when `--name <glob>` is given.
5
5
 
6
- use super::drives::DriveItem;
6
+ use super::drives::{DriveItem, encode_path_segments};
7
7
  use super::{GraphClient, PagedResponse};
8
8
  use crate::error::Result;
9
+ use crate::reference::percent_decode;
9
10
 
10
11
  pub(crate) struct SearchResult {
11
12
  pub(crate) items: Vec<DriveItem>,
@@ -16,39 +17,73 @@ pub(crate) struct SearchResult {
16
17
  pub(crate) fetched_url: String,
17
18
  }
18
19
 
19
- /// Execute a drive search. `page_url` is the full Graph URL to fetch;
20
- /// when `None` the default search URL is constructed from `drive_id` and `query`.
20
+ /// Execute a search scoped to `folder` (library-relative, `""` or `/` for the
21
+ /// whole drive). `page_url` is the full Graph URL to fetch; when `None` the
22
+ /// first-page search URL is built from `drive_id`, `folder` and `query`.
21
23
  pub(crate) async fn search(
22
24
  graph: &GraphClient,
23
25
  drive_id: &str,
26
+ folder: &str,
24
27
  query: &str,
25
28
  page_url: Option<&str>,
26
29
  ) -> Result<SearchResult> {
27
30
  let api = match page_url {
28
31
  Some(url) => url.to_string(),
29
- None => build_search_url(&format!("drives/{drive_id}"), query),
32
+ None => build_search_url(drive_id, folder, query),
30
33
  };
31
34
  // Resolve to a full absolute URL so the cursor stored in `fetched_url`
32
35
  // is always a complete URL (required by the host-validation check on decode).
33
36
  let absolute_url = graph.url(&api).await;
34
37
  let page: PagedResponse<DriveItem> = graph.get_json(&absolute_url).await?;
38
+ let items = page
39
+ .value
40
+ .into_iter()
41
+ .filter(|item| !known_outside(item, folder))
42
+ .collect();
35
43
  Ok(SearchResult {
36
- items: page.value,
44
+ items,
37
45
  next_url: page.next_link,
38
46
  fetched_url: absolute_url,
39
47
  })
40
48
  }
41
49
 
42
- /// Build the Graph API path for a drive search request.
50
+ /// Whether `item`'s parent path proves it lies outside `folder`.
51
+ ///
52
+ /// The search request is already scoped to the folder; this check guards
53
+ /// against the service widening that scope. Items whose `parentReference`
54
+ /// carries no path cannot be placed, so they are left to the server's scope.
55
+ fn known_outside(item: &DriveItem, folder: &str) -> bool {
56
+ let folder = folder.trim_matches('/');
57
+ if folder.is_empty() {
58
+ return false;
59
+ }
60
+ let Some((_, parent)) = item
61
+ .parent_reference
62
+ .as_ref()
63
+ .and_then(|p| p.path.split_once(':'))
64
+ else {
65
+ return false;
66
+ };
67
+ let parent = percent_decode(parent.trim_matches('/')).to_ascii_lowercase();
68
+ let folder = folder.to_ascii_lowercase();
69
+ !(parent == folder || parent.starts_with(&format!("{folder}/")))
70
+ }
71
+
72
+ /// Build the Graph API path for a search under `folder` of drive `drive_id`.
43
73
  ///
44
- /// The `drive_path` is a bare path prefix such as `"drives/{id}"`.
45
74
  /// OData single-quote escaping is applied first (doubling `'` to `''`),
46
75
  /// then the result is percent-encoded so reserved URL characters like
47
76
  /// `&`, `#`, `=`, and space are never interpolated raw into the URL.
48
- pub(super) fn build_search_url(drive_path: &str, query: &str) -> String {
77
+ pub(super) fn build_search_url(drive_id: &str, folder: &str, query: &str) -> String {
49
78
  let odata_escaped = query.replace('\'', "''");
50
79
  let encoded = url_encode_query(&odata_escaped);
51
- format!("/{drive_path}/root/search(q='{encoded}')")
80
+ let folder = folder.trim_matches('/');
81
+ let item = if folder.is_empty() {
82
+ "root".to_string()
83
+ } else {
84
+ format!("root:/{}:", encode_path_segments(folder))
85
+ };
86
+ format!("/drives/{drive_id}/{item}/search(q='{encoded}')")
52
87
  }
53
88
 
54
89
  /// Percent-encode a string using the RFC 3986 unreserved character set,
@@ -124,7 +159,7 @@ mod tests {
124
159
 
125
160
  #[test]
126
161
  fn build_search_url_percent_encodes_reserved_characters() {
127
- let url = build_search_url("drives/D1", "foo & bar=baz#frag");
162
+ let url = build_search_url("D1", "", "foo & bar=baz#frag");
128
163
  // Reserved characters must be percent-encoded.
129
164
  assert!(
130
165
  !url.contains(" & "),
@@ -140,7 +175,7 @@ mod tests {
140
175
 
141
176
  #[test]
142
177
  fn build_search_url_odata_escapes_single_quotes() {
143
- let url = build_search_url("drives/D1", "Bob's");
178
+ let url = build_search_url("D1", "", "Bob's");
144
179
  // OData: single quote doubled, then the doubled single quote is percent-encoded.
145
180
  // ' becomes '' in OData, and '' becomes %27%27 in URL encoding.
146
181
  assert!(
@@ -151,7 +186,7 @@ mod tests {
151
186
 
152
187
  #[test]
153
188
  fn build_search_url_plain_alphanumeric_is_unchanged() {
154
- let url = build_search_url("drives/D1", "quarterly-report_2025.xlsx");
189
+ let url = build_search_url("D1", "", "quarterly-report_2025.xlsx");
155
190
  assert!(
156
191
  url.contains("quarterly-report_2025.xlsx"),
157
192
  "unreserved chars must not be encoded; got {url}"
@@ -160,6 +160,32 @@ fn takes_value(arg: &std::ffi::OsStr) -> bool {
160
160
  })
161
161
  }
162
162
 
163
+ /// Condense clap's rendered error into a one-line message.
164
+ ///
165
+ /// Clap puts the summary on the first line and lists the offending arguments
166
+ /// (for example missing `<SITE>`) on indented lines directly below it. Those
167
+ /// lines carry the actionable part, so they are appended to the summary. A
168
+ /// blank line ends the detail block; tips and usage come after it.
169
+ fn clap_error_message(rendered: &str) -> String {
170
+ let mut lines = rendered.lines();
171
+ let summary = lines
172
+ .next()
173
+ .unwrap_or("invalid arguments")
174
+ .trim_start_matches("error: ")
175
+ .trim_end();
176
+ let details: Vec<&str> = lines
177
+ .take_while(|line| line.starts_with(char::is_whitespace) && !line.trim().is_empty())
178
+ .map(str::trim)
179
+ .collect();
180
+ if details.is_empty() {
181
+ summary.to_string()
182
+ } else if summary.ends_with(':') {
183
+ format!("{summary} {}", details.join(", "))
184
+ } else {
185
+ format!("{summary}: {}", details.join(", "))
186
+ }
187
+ }
188
+
163
189
  #[tokio::main]
164
190
  async fn main() -> ExitCode {
165
191
  let args = rewrite_argv(std::env::args_os());
@@ -191,14 +217,7 @@ async fn main() -> ExitCode {
191
217
  format
192
218
  };
193
219
  let out = OutputConfig::new(format, false);
194
- let msg = e.to_string();
195
- let first_line = msg
196
- .lines()
197
- .next()
198
- .unwrap_or("invalid arguments")
199
- .trim_start_matches("error: ")
200
- .to_string();
201
- let exit = out.render_error(&CliError::Input(first_line));
220
+ let exit = out.render_error(&CliError::Input(clap_error_message(&e.to_string())));
202
221
  return ExitCode::from(exit as u8);
203
222
  }
204
223
  };
@@ -16,6 +16,16 @@ pub(crate) fn record_page(seen: &mut HashSet<String>, url: &str) -> Result<()> {
16
16
  Ok(())
17
17
  }
18
18
 
19
+ /// Size of the complete result set, when this response alone establishes it.
20
+ ///
21
+ /// A response that started at the first item (`resumed == false`) and reached
22
+ /// the end (`has_next == false`) holds every item, so its length is the total.
23
+ /// Otherwise the items outside this response are uncounted and the total is
24
+ /// unknown, which callers report as `null` rather than the page size.
25
+ pub(crate) fn observed_total(resumed: bool, has_next: bool, returned: usize) -> Option<usize> {
26
+ (!resumed && !has_next).then_some(returned)
27
+ }
28
+
19
29
  #[derive(serde::Serialize, serde::Deserialize)]
20
30
  #[serde(deny_unknown_fields)]
21
31
  struct OffsetCursor {
@@ -30,7 +30,7 @@ pub struct ParsedRef {
30
30
  pub path: String,
31
31
  }
32
32
 
33
- fn percent_decode(input: &str) -> String {
33
+ pub(crate) fn percent_decode(input: &str) -> String {
34
34
  // Lightweight percent-decoder — handles `%20` etc. without pulling in another dep.
35
35
  let bytes = input.as_bytes();
36
36
  let mut out = Vec::with_capacity(bytes.len());
@@ -214,7 +214,8 @@ fn folder_api(client: &RestClient, site: &Site, server_relative: &str) -> Result
214
214
  }
215
215
 
216
216
  /// Assemble a folder's children from every REST collection page. `fetched_url`
217
- /// remains the folder URL so CLI cursors can resume within the combined result.
217
+ /// remains the folder URL so CLI cursors can resume within the combined result,
218
+ /// and the folder's full child count is known on every call.
218
219
  pub(crate) async fn list_children(
219
220
  client: &RestClient,
220
221
  site: &Site,
@@ -239,6 +240,7 @@ pub(crate) async fn list_children(
239
240
  .collect();
240
241
  items.extend(files.into_iter().map(|f| file_item(client, drive, f)));
241
242
  Ok(ListChildrenResult {
243
+ folder_total: Some(items.len()),
242
244
  items,
243
245
  next_url: None,
244
246
  fetched_url: folder_url,