Входни данни, CLI

27 ноември 2018

Административни неща

Административни неща

Административни неща

Преговор

Event emitter

Преговор

Event emitter

Преговор

Event emitter

Преговор

Event emitter

Преговор

Event emitter

Преговор

Event emitter

Преговор

Event emitter

Домашно 2

Demo

Домашно 2

Demo

Домашно 2

Demo

Домашно 2

Demo

Hangman

Demo

Пълния код: rust-hangman

Данни за играта?

Данни за играта?

Данни за играта?

Данни за играта?

Локално инсталиране на пакет

Локално инсталиране на пакет

Локално инсталиране на пакет

Локално инсталиране на пакет

Debug-ване

ENV vars

1 2 3 4 5 6 7 8
pub fn clear_screen() {
    if env::var("DEBUG").is_ok() {
        return;
    }

    print!("{}[2J", 27 as char);
    print!("{}[1;1H", 27 as char);
}
1 2
$ DEBUG=1 cargo run some-file.txt
$ DEBUG=1 hangman some-file.txt

По-сложна обработка на аргументи чрез structopt

1 2 3 4
[dependencies]
rand = "*"
structopt = "*"
structopt-derive = "*"

По-сложна обработка на аргументи чрез structopt

1 2 3 4
$ hangman --wordlist=words.txt --attempts=10 --debug
$ hangman -w words.txt -a 10 -d
$ hangman --help
$ hangman --version

По-сложна обработка на аргументи чрез structopt

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
extern crate structopt;
#[macro_use]
extern crate structopt_derive;
use structopt::StructOpt;

#[derive(StructOpt, Debug)]
#[structopt(name="hangman", about="A game of Hangman")]
pub struct Options {
    #[structopt(short="w", long="wordlist", help="The path to a word list")]
    wordlist_path: Option<String>,

    #[structopt(short="a", long="attempts", help="The number of attempts to guess the word", default_value="10")]
    attempts: u32,

    #[structopt(short="d", long="debug", help="Show debug info")]
    debug: bool,
}

Ограничения на structopt

Ограничения на structopt

Ограничения на structopt

Ограничения на structopt

Още полезни пакети

Още полезни пакети

Още полезни пакети

Още полезни пакети

Още полезни пакети

Въпроси