Skip to content

Commit

Permalink
Lots of progress. First runnable example.
Browse files Browse the repository at this point in the history
  • Loading branch information
BurntSushi committed Jun 29, 2014
1 parent 0177071 commit 28d683b
Show file tree
Hide file tree
Showing 7 changed files with 2,316 additions and 1,049 deletions.
30 changes: 19 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
RUSTC ?= rustc
RUSTDOC ?= rustdoc
BUILD_DIR ?= ./build
RUST_PATH ?= $(BUILD_DIR)
BUILD ?= ./build
TARGET ?= ./target
RUST_PATH ?= -L $(BUILD) -L target
# RUSTFLAGS ?= --opt-level=3
RUSTFLAGS ?=
RUSTTESTFLAGS ?=
LIB_NAME = docopt
LIB ?= $(BUILD_DIR)/.libregex.timestamp
LIB_FILES = src/lib.rs src/synonym.rs
LIB ?= $(BUILD)/.libregex.timestamp
LIB_FILES = src/lib.rs src/parse.rs src/synonym.rs
TEST_FILES = src/test.rs
ARGS ?=

all: $(LIB)

install:
cargo-lite install

$(LIB): $(LIB_FILES)
@mkdir -p $(BUILD_DIR)
$(RUSTC) $(RUSTFLAGS) ./src/lib.rs --out-dir=$(BUILD_DIR)
@mkdir -p $(BUILD)
$(RUSTC) $(RUSTFLAGS) ./src/lib.rs --out-dir=$(TARGET)
@touch $(LIB)

docs: $(LIB_FILES)
rm -rf doc
$(RUSTDOC) -L $(RUST_PATH) --test ./src/lib.rs
$(RUSTDOC) -L $(RUST_PATH) ./src/lib.rs
$(RUSTDOC) $(RUST_PATH) --test ./src/lib.rs
$(RUSTDOC) $(RUST_PATH) ./src/lib.rs
# WTF is rustdoc doing?
chmod 755 doc
in-dir doc fix-perms
Expand All @@ -33,19 +35,25 @@ test: build/tests
RUST_TEST_TASKS=1 RUST_LOG=$(LIB_NAME) ./build/tests

build/tests: $(LIB) $(TEST_FILES)
$(RUSTC) $(RUSTTESTFLAGS) -L $(RUST_PATH) --test src/lib.rs -o ./build/tests
$(RUSTC) $(RUSTTESTFLAGS) $(RUST_PATH) --test src/lib.rs -o ./build/tests

scratch: build/scratch
RUST_TEST_TASKS=1 RUST_LOG=$(LIB_NAME) ./build/scratch

build/scratch: $(LIB) scratch.rs
$(RUSTC) -L $(BUILD_DIR) $(RUSTTESTFLAGS) scratch.rs -o ./build/scratch
$(RUSTC) -L $(BUILD) $(RUSTTESTFLAGS) scratch.rs -o ./build/scratch

ex_%: build/%
./build/$* $(ARGS)

build/%: examples/%.rs $(LIB)
$(RUSTC) $(RUST_PATH) --out-dir $(BUILD) $<

ctags:
ctags --recurse --options=ctags.rust --languages=Rust

clean:
rm -f $(BUILD_DIR)/.*.timestamp $(BUILD_DIR)/*
rm -f $(BUILD)/.*.timestamp $(BUILD)/*

push:
git push origin master
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,13 @@ Docopt for Rust with automatic type based decoding (i.e., data validation).

Licensed under the [UNLICENSE](http://unlicense.org).

Currently a work in progress.
Check out
[examples/no_macro.rs](https://github.com/BurntSushi/docopt.rs/blob/master/examples/no_macro.rs)
for a glimpse at Docopt in action. (As the name of the example suggests, there
is no macro support yet.)

### TODO

* Testing.
* Macro.

48 changes: 48 additions & 0 deletions examples/no_macro.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
extern crate docopt;

use docopt::docopt;

static docstr: &'static str = "
Naval Fate.
Usage:
naval_fate.py ship new <name>...
naval_fate.py ship <name> move <x> <y> [--speed=<kn>]
naval_fate.py ship shoot <x> <y>
naval_fate.py mine (set|remove) <x> <y> [--moored | --drifting]
naval_fate.py (-h | --help)
naval_fate.py --version
Options:
-h --help Show this screen.
--version Show version.
--speed=<kn> Speed in knots [default: 10].
--moored Moored (anchored) mine.
--drifting Drifting mine.
";

fn main() {
let args = docopt(docstr);
// If you invoke with:
//
// no_macro ship Guardian move 100 150 --speed=15
//
// then you should get the following map:
//
// --drifting => Switch(false)
// -h, --help => Switch(false)
// --moored => Switch(false)
// --speed => Plain(Some(15))
// --version => Switch(false)
// <name> => List([Guardian])
// <x> => Plain(Some(100))
// <y> => Plain(Some(150))
// mine => Switch(false)
// move => Switch(true)
// new => Switch(false)
// remove => Switch(false)
// set => Switch(false)
// ship => Switch(true)
// shoot => Switch(false)
println!("{}", args);
}
Loading

0 comments on commit 28d683b

Please sign in to comment.