Skip to content

Commit 309af5e

Browse files
authored
Merge pull request #165 from cooklang/chore/optional-self-update
fix: make self-update optional
2 parents edf320a + 96691aa commit 309af5e

7 files changed

Lines changed: 46 additions & 4 deletions

File tree

.github/workflows/test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ jobs:
8888
run: cargo build --release --verbose
8989
if: matrix.rust == 'stable'
9090

91+
- name: Build without self-update feature
92+
run: cargo build --release --no-default-features --verbose
93+
if: matrix.rust == 'stable'
94+
9195
coverage:
9296
name: Code Coverage
9397
runs-on: ubuntu-latest

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ description = "A command-line interface for managing and working with Cooklang r
66
license = "MIT"
77
include = ["/src", "/Cargo.toml", "/Cargo.lock", "/README.md", "/templates", "/static"]
88

9+
[features]
10+
default = ["self-update"]
11+
self-update = ["dep:self_update"]
12+
913
[lib]
1014
name = "cookcli"
1115
path = "src/lib.rs"
@@ -40,7 +44,7 @@ openssl = { version = "0.10", features = ["vendored"] }
4044
regex = "1"
4145
rust-embed = "8"
4246
scraper = "0.20"
43-
self_update = { version = "0.41", default-features = false, features = ["archive-tar", "archive-zip", "compression-flate2", "rustls"] }
47+
self_update = { version = "0.41", default-features = false, features = ["archive-tar", "archive-zip", "compression-flate2", "rustls"], optional = true }
4448
serde = "1.0"
4549
serde_json = "1.0"
4650
serde_yaml = "0.9"

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,23 @@ cargo build --release
124124
# Binary will be at target/release/cook
125125
```
126126
127+
#### Building without Self-Update
128+
129+
By default, CookCLI includes a self-update feature. To build without this feature (useful for CI/CD pipelines, package managers, or environments where auto-update is not desired):
130+
131+
```bash
132+
# Build without self-update feature
133+
cargo build --release --no-default-features
134+
135+
# This disables the 'self-update' feature flag while keeping all other functionality
136+
```
137+
138+
Use cases for disabling self-update:
139+
* Package manager distributions (Homebrew, apt, etc.)
140+
* CI/CD pipelines where version control is managed externally
141+
* Corporate environments with restricted network access
142+
* When distributing through official release channels
143+
127144
### Development Setup
128145
129146
For development with hot-reload of CSS changes:

src/args.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030

3131
use clap::{Parser, Subcommand};
3232

33-
use crate::{doctor, import, pantry, recipe, report, search, seed, server, shopping_list, update};
33+
#[cfg(feature = "self-update")]
34+
use crate::update;
35+
use crate::{doctor, import, pantry, recipe, report, search, seed, server, shopping_list};
3436

3537
#[derive(Parser, Debug)]
3638
#[command(
@@ -201,9 +203,11 @@ pub enum Command {
201203
/// cook update # Download and install latest version
202204
/// cook update --check-only # Check for updates without installing
203205
/// cook update --force # Force reinstall even if up to date
206+
#[cfg(feature = "self-update")]
204207
#[command(
205208
alias = "u",
206209
long_about = "Check for and install updates to CookCLI from GitHub releases"
207210
)]
211+
#[cfg(feature = "self-update")]
208212
Update(update::UpdateArgs),
209213
}

src/doctor.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,17 @@ pub fn run(ctx: &Context, args: DoctorArgs) -> Result<()> {
108108
println!("Running all doctor checks...\n");
109109

110110
// Check for updates
111-
println!("=== Version Check ===");
112-
check_for_updates();
111+
#[cfg(feature = "self-update")]
112+
{
113+
println!("=== Version Check ===");
114+
check_for_updates();
115+
}
116+
#[cfg(not(feature = "self-update"))]
117+
{
118+
println!("=== Version Check ===");
119+
println!("ℹ️ Self-update is disabled in this build.");
120+
println!(" Please update through your package manager or build from source.");
121+
}
113122

114123
println!("\n=== Recipe Validation ===");
115124
run_validate(
@@ -131,6 +140,7 @@ pub fn run(ctx: &Context, args: DoctorArgs) -> Result<()> {
131140
}
132141
}
133142

143+
#[cfg(feature = "self-update")]
134144
fn check_for_updates() {
135145
match crate::update::check_for_updates() {
136146
Ok(Some(new_version)) => {

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub mod search;
1111
pub mod seed;
1212
pub mod server;
1313
pub mod shopping_list;
14+
#[cfg(feature = "self-update")]
1415
pub mod update;
1516

1617
// Other modules

src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ mod search;
4444
mod seed;
4545
mod server;
4646
mod shopping_list;
47+
#[cfg(feature = "self-update")]
4748
mod update;
4849

4950
// other modules
@@ -72,6 +73,7 @@ pub fn main() -> Result<()> {
7273
Command::Report(args) => report::run(&ctx, args),
7374
Command::Doctor(args) => doctor::run(&ctx, args),
7475
Command::Pantry(args) => pantry::run(&ctx, args),
76+
#[cfg(feature = "self-update")]
7577
Command::Update(args) => update::run(args),
7678
}
7779
}

0 commit comments

Comments
 (0)