namespace ensemble create : limited scope

44 views Asked by At

I created this :

# file1.tcl
namespace eval myNS {
    namespace ensemble create -command ::make
    namespace export cmd1 cmd2 cmd3
}

I've just realised that if I add another procedure cmd4 to my export namespace in another file like this:

# file2.tcl
namespace eval myNS {
    namespace export cmd4
}

I can also write like this make cmd4 $args

My question is: Is it possible to limit it to cmd1 cmd2 cmd3 commands?

1

There are 1 answers

1
Shawn On BEST ANSWER

You can use the -subcommands option when creating the ensemble to restrict what's available instead of the default of all exported commands:

namespace eval myNS {
    namespace ensemble create -command ::make -subcommands {cmd1 cmd2 cmd3}
    namespace export cmd1 cmd2 cmd3
}

After loading both files, make cmd4 will give an error, but myNS::cmd4 can still be imported with namespace import or called directly; just not through the ensemble.