This seems a bit better:

define foo(
     Enum["present", "absent"] $ensure                     = "present",
     Optional[String]                $ssh_authorized_file   = undef,
     Optional[String]                $email                       = undef,
     Optional[Integer]               $uid                          = undef,
     Optional[Integer]               $gid                          = undef,
     Variant[Boolean, String]    $sudoer                     = false,
     Boolean                           $setup_shell              = false,
     Boolean                           $setup_rbenv              = false
   ) {

It's relatively easy to achieve with Tabular but I do agree on the advanced
structs, that's some crazy.

This is the best that I could do:

Struct[
  {
    mode                => Enum[read, write, update],
    path                  => Optional[String[1]],
    NotUndef[owner] => Optional[String[1]]
 }
]

I honestly have no idea if that will process correctly though, it's
massively tedious, and it would probably need a lot of commenting.

Trevor

On Thu, Jul 30, 2015 at 10:36 AM, R.I.Pienaar <[email protected]> wrote:

> hello,
>
> I've done a few little things with the type system and really like what it
> achieves,
> was able to find a few bad data items in my hiera data and it saves on a
> lot of the
> super annoying validation function calls.
>
> The syntax though is pretty difficult to use, consider:
>
>    define foo(
>      Enum["present", "absent"] $ensure       = "present",
>      Optional[String] $ssh_authorized_file   = undef,
>      Optional[String] $email                 = undef,
>      Optional[Integer] $uid                  = undef,
>      Optional[Integer] $gid                  = undef,
>      Variant[Boolean, String] $sudoer        = false,
>      Boolean $setup_shell                    = false,
>      Boolean $setup_rbenv                    = false
>    ) {
>
> So this has a few issues for me:
>
> Reading it, I just don't see the property names now, its become a real
> effort
> to read this.
>
>    $ssh_authorized_file Optional[String] = undef,
>
> seems better for this use case to me and this is probably going to be the
> most
> often used use case.
>
> This gets much worse when we involve more complex type definitions, I
> can't imagine
> ever using a full on Struct definition here for example it would render it
> entirely
> unreadable and be impossible to maintain
>
> How would you ever fit this into a param declaration and maintain
> readability:
>
>    Struct[{mode            => Enum[read, write, update],
>            path            => Optional[String[1]],
>            NotUndef[owner] => Optional[String[1]]}]
>
> This leads to my 2nd question, I couldn't find a way to make my own
> abstract
> types.
>
> Consider this hypothetical with made up syntax and all:
>
>    site.pp:
>    typedef MyData Struct[{mode => Enum[read, write, update],
>                           path            => Optional[String[1]],
>                           NotUndef[owner] => Optional[String[1]]}]
>
>    foo.pp:
>    define foo(Mydata $data) {
>
> this would improve matters a whole lot.  Does a typedef like feature
> exist? I couldn't
> find anything and tried a few things but failed
>
>
> ---
> R.I.Pienaar
>
> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/143546306.116227.1438266987939.JavaMail.zimbra%40devco.net
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Trevor Vaughan
Vice President, Onyx Point, Inc
(410) 541-6699

-- This account not approved for unencrypted proprietary information --

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/CANs%2BFoXyp8fCPdna4v_%2B1oMwWfjgRu9X4fT6ZHONnfz5ZfdM_g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to