Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions lib/options.nix
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,24 @@ rec {
visible = opt.visible or true;
readOnly = opt.readOnly or false;
type = opt.type.name or null;
}
// (if opt ? example then { example = scrubOptionValue opt.example; } else {})
// (if opt ? default then { default = scrubOptionValue opt.default; } else {})
// (if opt ? defaultText then { default = opt.defaultText; } else {});
};
docOptionDefault =
if opt ? defaultText then { default = opt.defaultText; }
else if opt ? default then { default = scrubOptionValue opt.default; }
else { };
docOptionExample =
if opt ? example then { example = scrubOptionValue opt.example; }
else if opt.type == lib.types.bool then
{ example = !docOptionDefault.default or false; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: !(docOptionDefault.default or false)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll change that to improve readability.

else if opt ? type && isBool (docOptionDefault.default or null) && opt.type.check (!docOptionDefault.default) then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In opt.type.check (!docOptionDefault.default), the attribute default might not exists, and raise an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should never happen since it's only evaluated if isBool (docOptionDefault.default or null)

{ example = !docOptionDefault.default or false; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: !(… or …)
nit: factor this expression in a let … in ….

Copy link
Contributor Author

@groxxda groxxda Oct 31, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll check if I can factor that out, but I'd rather not add a let.
Reading it again it's strange I check for opt.type == bool and in the else case check opt ? type. This looks wrong 😕

else { };

subOptions =
let ss = opt.type.getSubOptions opt.loc;
in if ss != {} then optionAttrSetToDocList' opt.loc ss else [];
in
[ docOption ] ++ subOptions) (collect isOption options);
[ (docOption // docOptionDefault // docOptionExample) ] ++ subOptions) (collect isOption options);


/* This function recursively removes all derivation attributes from
Expand Down