Skip to content

Commit

Permalink
initial ARGV parsing & tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
bakkdoor committed Apr 27, 2012
1 parent 4f2ce48 commit 5afd5fc
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 1 deletion.
5 changes: 5 additions & 0 deletions bin/fake
@@ -0,0 +1,5 @@
#!/usr/bin/env fancy

require: "../lib/fake"

Fake CLI handle_arguments: ARGV
21 changes: 20 additions & 1 deletion lib/fake.fy
@@ -1 +1,20 @@
class Fake
class Fake

require: "fake/task"
require: "fake/task_builder"
require: "fake/cli"

class Fake {
def Fake tasks: block {
TasksBuilder new: block . tasks
}

def Fake read_fakefile: fakefile ("Fakefile") {
try {
File eval: fakefile
} catch Errno::ENOENT => e {
*stderr* println: e
System exit: 1
}
}
}
19 changes: 19 additions & 0 deletions lib/fake/cli.fy
@@ -0,0 +1,19 @@
class Fake {
class CLI
}

require: "cli/args"

class Fake {
class CLI {
def CLI handle_arguments: argv {
parse_argv: argv
Fake read_fakefile: @fakefile
}

def CLI parse_argv: argv {
@args = Args new: argv
@fakefile = @args parse_option: "-f"
}
}
}
18 changes: 18 additions & 0 deletions lib/fake/cli/args.fy
@@ -0,0 +1,18 @@
class Fake {
class CLI {
class Args {
Defaults = <[
"-f" => "Fakefile"
]>

def initialize: @argv
def parse_option: opt {
if: (@argv index: opt) then: |idx| {
@argv[idx + 1]
} else: {
Defaults[opt]
}
}
}
}
}
10 changes: 10 additions & 0 deletions lib/fake/task.fy
@@ -0,0 +1,10 @@
class Fake {
class Task {
read_slots: ('name, 'block, 'dependencies)
def initialize: @name block: @block ({}) dependencies: @dependencies ([]);

def run {
@dependencies
}
}
}
11 changes: 11 additions & 0 deletions lib/fake/task_builder.fy
@@ -0,0 +1,11 @@
class Fake {
class TaskBuilder {
def initialize: @block {
}

def tasks {
# TODO
[]
}
}
}
15 changes: 15 additions & 0 deletions tests/cli/args.fy
@@ -0,0 +1,15 @@
require: "lib/fake/cli/args"

FancySpec describe: Fake CLI Args with: {
def args: argv {
Fake CLI Args new: argv
}

it: "returns the default value" for: 'parse_option: when: {
args: [] . parse_option: "-f" . is: $ Fake CLI Args Defaults["-f"]
}

it: "returns the passed in value" for: 'parse_option: when: {
args: ["-f", "MyCustomFakeFile"] . parse_option: "-f" . is: $ "MyCustomFakeFile"
}
}

0 comments on commit 5afd5fc

Please sign in to comment.