Skip to content

Commit

Permalink
cleanup lib/argv.fy and add docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
bakkdoor committed Nov 14, 2012
1 parent 0117dcf commit 12ca2e6
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions lib/argv.fy
Expand Up @@ -3,10 +3,16 @@ ARGV documentation: """
arguments passed to a Fancy programm before it starts executing.
"""

def ARGV for_option: op_name do: block {
"Runs a given block if an option is in ARGV."
def ARGV for_option: option_name do: block {
"""
@option_name Name of command-line option.
@block @Block@ to be called with value of command-line option @option_name, if given.
@return @true, if @option_name was found in @ARGV and @block was called, @false otherwise.
Calls a given Block if a command-line option is in @ARGV.
"""

ARGV index: op_name . if_true: |idx| {
if: (ARGV index: option_name) then: |idx| {
if: (block arity > 0) then: {
if: (ARGV[idx + 1]) then: |arg| {
block call: [arg]
Expand All @@ -17,25 +23,24 @@ def ARGV for_option: op_name do: block {
block call
ARGV remove_at: idx
}
return true
}
return false
}

def ARGV for_options: op_names do: block {
"Runs a given block if any of the given options is in ARGV."
def ARGV for_options: option_names do: block {
"""
@option_names @Fancy::Enumerable@ of related command-line option names.
@block @Block@ to be called with value of any command-line option in @option_names, if given.
@return @true, if any of @option_names was found in @ARGV and @block was called, @false otherwise.
Calls a given Block if any of the given command-line options are in @ARGV.
"""

op_names size times: |i| {
if: (ARGV index: (op_names[i])) then: |idx| {
if: (block arity > 0) then: {
if: (ARGV[idx + 1]) then: |arg| {
block call: [arg]
ARGV remove_at: idx
ARGV remove_at: idx
}
} else: {
block call
ARGV remove_at: idx
}
option_names each: |option_name| {
if: (ARGV for_option: option_name do: block) then: {
return true
}
}
return false
}

0 comments on commit 12ca2e6

Please sign in to comment.