Comments (3)
@kbknapp sorry to bother you.
For this feature I would like warn users and ask them if they want to continue. Something like this:
Copying the theme to 'src/theme' could overwrite files already present.
Are you sure you want to continue? (y/n)
Is that functionality in clap
, or do you know an easy way of doing this? :)
from mdbook.
No worries π
There isn't anything like a confirm()
in clap
(although that's not a bad idea!). I've found it's usually also a good idea to give the user a chance to skip the confirmation if they know what they're doing (by adding --noconfirm
or --force
, etc.)
The best way to do this is:
use std::io::{self, Write, Read};
fn main() {
let m = // everything normal
// just add an arg that uses --theme
// and one for skipping such as --noconfirm
.get_matches();
if m.is_present("theme") && !m.is_present("noconfirm") {
if !confirm() {
println!("exiting...");
::std::process::exit(0);
}
}
}
fn confirm() -> bool {
print!("Copying the theme to 'src/theme' could overwrite files already present.\n\n\
Are you sure you want to continue? (y/n): ");
io::stdout().flush().unwrap();
let mut s = String::new();
io::stdin().read_line(&mut s).ok();
match &*s.trim() {
"Y" | "y" => true,
_ => false
}
}
Edit: Fixed formatting
Edit 2: Also, I've vote π on doing all the init when a user does init --theme
. I'd find it confusing to run
$ mdbook init --theme sometheme
$ mdbook init
from mdbook.
Nice! Thank you for that :)
There isn't anything like a confirm() in clap (although that's not a bad idea!).
That would be a neat thing to have ;)
Also, I've vote π on doing all the init when a user does init --theme. I'd find it confusing to run...
I agree, the only reason I was hesitating is that you may want to copy the theme in an already existing project. And at that moment you don't want init
to mess up what you already have.
But I it's a better idea to implement init
so that it does not mess up an existing project when runned.
from mdbook.
Related Issues (20)
- Links with empty path cause error
- How to prevent the .git directory in the output directory from being deletedοΌ HOT 2
- Let all the output html files share the same one sidebar HOT 6
- Accessibility: New Markdown files must start with Heading Level 2 because Book Title is Heading level 1 HOT 4
- Support '/' shortcut to search
- Images with relative path not displayed on index.html HOT 1
- Figure out a strategy for updating public dependencies HOT 1
- 0.4.38 release has no assets HOT 2
- Is there a way to use own markdown short code templates? HOT 2
- Non-English search support HOT 5
- Replace icon fonts with SVG HOT 1
- Use capital letters to indicate the default value in (y/n) prompts
- serve only html backend
- Support for automated tests in languages other than Rust
- Exclude page from printing
- If `!search_config.copy_js`, then perform useless search indexing, and search is disabled
- feat(ux): add CMD+K support HOT 3
- Cannot load custom font files with 'mdbook serve' on macOS
- warn on orphan files
- Ordering of footnote HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mdbook.