保存可重複使用的選取
profile 是具名的打包選項集合,不是專案檔案的副本。需要反覆分享相同範圍時,可用它保存設定。本教學會建立 review、臨時覆寫、修改已存設定,再比較合併與取代。
用文字編輯器在新的 demo 資料夾建立以下檔案。檔名後方是內容;每個 ↵ 代表換行。請只使用示範值。接著在 demo 開啟終端機,不要沿用已有 .onesourcerc 的資料夾。
README.md: # Demosrc/main.rs: fn main() {}tests/smoke.rs: #[test] ↵ fn smoke() {}
需先能執行 onesource;尚未安裝請先看 安裝教學。除非步驟另有說明,本頁所有指令都從此資料夾執行。
起始資料夾不能有 .onesourcerc,本頁的 profile 步驟才會建立它。profile 指令只管理設定,不產生打包檔。
1. 建立、檢視與套用 profile
建立 review,設定只附加原始碼與大小上限。名稱放在 create 後,接下來的選項就是要保存的設定;--desc 方便日後辨識用途。
onesource profile create review -i "src/**" -m 100 --desc "Source review"預期看到 Created profile,並建立 demo/.onesourcerc,不產生打包檔。想精確確認存了什麼,可要求 JSON:
onesource profile show review --json{
"description": "Source review",
"include": "src/**",
"max_size": 100
}因為沒有指定 output_path、no_tree,所以也沒有儲存。--json 要求可供程式讀取的輸出;不加時 show 按類別列出設定,未存欄位標為 unset。需要選擇 profile 時,先列出名稱與描述:
onesource profile list應看到 review 與其描述。用 -p(--profile 縮寫)把它套用到預覽:
onesource -p review --dry-run預期只附加 src/main.rs。100 KiB 上限與原始碼篩選來自 review;dry-run 只影響當次執行。要寫入該選取,改用 onesource -p review。具名 profile 不繼承名為 default 的 profile。
2. 只覆寫當次執行,不保存
某次檢閱可能還需要測試。CLI include 只在當次取代已存 include,不是追加:
onesource -p review -i "src/**,tests/**" --dry-run預期附加 src/main.rs 與 tests/smoke.rs,而 max-size 仍為 100。再查看已存 profile:
onesource profile show review --json仍應為 "include": "src/**"。這樣可以先實驗、不影響未來執行。若要完全略過設定,使用 --no-config,即使帶 -p 也不載入。明確 --include="" 可取消當次 include 限制;--no-tree=false 可覆寫已存的 true 布林值。
3. 更新設定,或保存試好的指令
若要修改 profile、但不打包,使用 update。只更改明確提供的欄位,這叫合併:
onesource profile update review -x "tests/" --no-tree再次 show review,應保留 description、include、max_size,並新增 exclude、no_tree:
{
"description": "Source review",
"include": "src/**",
"exclude": "tests/",
"no_tree": true,
"max_size": 100
}也可以把已試好的指令明確設定保存到使用中 profile。以下把 README 加入未來檢閱,並恢復樹:
onesource -p review -i "src/**,README.md" --no-tree=false --save --dry-run預期有 Saved profile 訊息、樹,以及 README.md 與 src/main.rs 內容。show review 應變成 include="src/**,README.md"、no_tree=false;既有 exclude 與 max_size 保留。只儲存明確提供且可保存的選項,不存 dry-run 或 -p。有 --save 時,dry-run 仍會寫入設定。儲存早於掃描,掃描失敗不會撤銷。
若要替不帶 -p 的執行建立預設,可存到隱含的 default profile:
onesource --no-config -i "src/**" --save --dry-run這會建立或合併 default,不修改 review。新增具名 profile 建議用 create;--no-config -p NAME --save 也能建立,但啟用載入時要求不存在的具名 profile,會先失敗、無法儲存。
4. 完整取代,而非合併
舊欄位應全部移除時,才使用取代。以上一步的 profile 為起點,把它取代為只有 README 的 include:
onesource profile update review --replace -i "README.md"onesource profile show review --json{
"include": "README.md"
}description、exclude、no_tree、max_size 全部消失。未設定欄位回到預設,因此大小上限為 500 KiB、樹啟用。執行 onesource -p review --dry-run,確認只附加 README。
一般打包也支援 --save --replace。若要取代 review,而且不讓當次載入舊欄位,使用:
onesource --no-config -p review --save --replace -i "src/**" --dry-run預期已存 profile 只剩 include="src/**",預覽處理 main.rs。若不加 --no-config,當次仍可能使用先前載入的舊欄位,即使取代已從磁碟移除它們。一般執行 --replace 必須有 --save;profile update --replace 不必。
5. 改名、改描述或移除 profile
完成取代後,可把 review 改成更清楚的名稱:
onesource profile rename review backendlist 現在應顯示 backend、不再顯示 review。若要加新描述、不改選取:
onesource profile update backend --desc "Backend source"show backend 應包含 include 與 description。不再需要時刪除:
onesource profile delete backendlist 不再包含 backend。刪除 profile 只移除設定,不刪原始碼或打包檔。刪除 default 會讓未指定 profile 的執行回到內建設定。create 遇同名會失敗;rename 目標已存在會失敗;show/update/delete 要求指定 profile 存在。名稱只能是非空 ASCII 英數、句點、底線或連字號。
理解已存 JSON 與優先順序
確認已存 profile 後,可用文字編輯器開啟 .onesourcerc。頂層 profiles 物件將名稱對應到選項物件。JSON 用底線(output_path),CLI 用連字號(--output-path);description 對應 --desc。手動設定時,先儲存有效 JSON,再用 profile show 驗證、最後打包。以下是所有欄位範例,與流程中逐步變化的 profile 分開:
JSON 位於掃描根目錄/.onesourcerc。明確 CLI 值優先於選定 profile,最後套用內建預設值。default profile 可省略;具名 profile 不繼承它。serde 會忽略未知欄位。省略或 null 使用預設/繼承;空字串與 false 是明確值。欄位型別、預設及效果列於 CLI 參考。只會儲存以下欄位;path、profile 選擇、copy、dry_run、save、replace、no_config、show_arg 不會儲存。
{
"profiles": {
"default": {
"description": "原始碼檢閱",
"output_path": "review.onesource",
"include": "src/**",
"exclude": "src/legacy/",
"tree_include": "",
"tree_exclude": "target/",
"max_size": 500,
"no_ignore": false,
"tree_no_ignore": false,
"no_tree": false,
"no_blacklist": false
}
}
}CLI 明確值優先於選定 profile,再套內建預設。default 只在未帶 -p 時使用,不是繼承基底。設定從掃描根目錄讀取;管理其他資料夾可用 onesource /path/to/project profile list。管理指令即使頂層 --no-config 仍讀設定。請避免同時手動修改:設定直接寫入,不是原子操作。
舊版別名與復原
既有腳本可用 profile ls 代替 list,profile rm NAME 代替 delete。隱藏的舊版描述指令必須帶 -p:
onesource profile desc "Backend source" -p default要求 default 已存在,並合併更新描述;新腳本應改用 profile update default --desc "Backend source"。list/show 的 --json 是布林旗標(預設 false)。create/update 接受 CLI 參考 的可保存選項;update --replace 是布林動作旗標、預設 false。每個子指令都有 --help。
設定損壞或使用舊版平面格式時,先備份並依 設定遷移教學 處理。--no-config 可略過一般載入,但不略過 --save 所需的設定讀取。清除 include 限制、不刪欄位可用 --include="";要移除欄位,需取代 profile 或編輯 JSON。