Skip to content

Commit

Permalink
fix: test vector help text (#657)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajewellamz authored Sep 1, 2024
1 parent 5b3dcc6 commit 0fedaf1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ PROJECT_ROOT := $(abspath $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))

# This finds all Dafny projects in this repository
# This makes building root level targets for each project easy
PROJECTS = $(shell find . -mindepth 2 -maxdepth 2 -type f -name "Makefile" | xargs dirname | xargs basename)
PROJECTS = $(shell find . -mindepth 2 -maxdepth 2 -type f -name "Makefile" | fgrep -v smithy-dafny | xargs dirname | xargs basename)

verify:
$(foreach PROJECT, $(PROJECTS), \
Expand Down
29 changes: 19 additions & 10 deletions StandardLibrary/src/GetOpt.dfy
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,15 @@ module {:options "-functionSyntax:4"} GetOpt {
}
}

predicate IsHelp(args : Parsed)
{
&& |args.params| != 0
&& args.params[0].name == HELP_STR
}

function {:tailrecursion} NeedsHelp(opts : Options, args : Parsed, prefix : string := "") : Option<string>
{
if |args.params| != 0 && args.params[0].name == HELP_STR then
if IsHelp(args) then
Some(GetHelp(opts, prefix))
else if args.subcommand.Some? then
var pos :- GetSubOptions(opts.params, args.subcommand.value.command);
Expand Down Expand Up @@ -613,16 +619,19 @@ module {:options "-functionSyntax:4"} GetOpt {

function /*{:tailrecursion}*/ PostProcess(opts : Options, args : Parsed) : Result<Parsed, string>
{
var newParams :- PostProcess2(opts.params, args.params);
if args.subcommand.Some? then
var optPos := GetSubOptions(opts.params, args.subcommand.value.command);
if optPos.Some? then
var sub :- PostProcess(opts.params[optPos.value].options, args.subcommand.value);
Success(args.(params := args.params + newParams, subcommand := Some(sub)))
else
Failure("Internal error in GetOpt::PostProcess")
if IsHelp(args) then
Success(args)
else
Success(args.(params := args.params + newParams))
var newParams :- PostProcess2(opts.params, args.params);
if args.subcommand.Some? then
var optPos := GetSubOptions(opts.params, args.subcommand.value.command);
if optPos.Some? then
var sub :- PostProcess(opts.params[optPos.value].options, args.subcommand.value);
Success(args.(params := args.params + newParams, subcommand := Some(sub)))
else
Failure("Internal error in GetOpt::PostProcess")
else
Success(args.(params := args.params + newParams))
}

predicate AllDigits(s : string)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ module {:options "-functionSyntax:4"} WrappedMaterialProvidersMain {
var parsedOptions? := GetOptions(vectorOptions, args);

if parsedOptions?.Success? {
var h := NeedsHelp(vectorOptions, parsedOptions?.value);
if h.Some? {
print h.value;
return;
}
var op? := ParseCommandLineOptions(parsedOptions?.value);

if op?.Success? {
Expand Down

0 comments on commit 0fedaf1

Please sign in to comment.