Module Functions – Prompted for nested mandatory arguments on import?

Welcome Forums General PowerShell Q&A Module Functions – Prompted for nested mandatory arguments on import?

Viewing 2 reply threads
  • Author
    Posts
    • #285568
      Participant
      Topics: 1
      Replies: 0
      Points: 16
      Rank: Member

      Heyo!

      I’m currently using the Public/Private folder paradigm in my modules. So far, so good. However, I’ve got a module with two functions, the main ‘public’ function has mandatory params and it calls a sibling function (also with mandatory params). When I import the module, the secondary module prompts me for the params, which I don’t want.

      If I remove the mandatory tags on the second function’s params, it imports OK…

      I don’t think I’ve seen this before, I’m sure it has to be a scoping thing. Do I have to hide the secondary function in Private? I’d like to expose it as a public function too.

    • #285613
      Senior Moderator
      Topics: 9
      Replies: 1449
      Points: 5,429
      Helping Hand
      Rank: Community MVP

      There is no such contract and no harm too. You can make it public if you see it relevant. When calling any function which has mandatory parameters, those mandatory inputs has to be passed.

    • #285670
      Participant
      Topics: 17
      Replies: 1957
      Points: 4,016
      Helping Hand
      Rank: Community Hero

      Are you sure you’re not calling it somewhere accidentally. It shouldn’t be calling functions to tell you something is mandatory, so in the PS1 import file it would be like this:

      When I was testing I didn’t remove the call and it was showing behavior like that.

Viewing 2 reply threads
  • You must be logged in to reply to this topic.