elves / elvish

Powerful scripting language & versatile interactive shell
https://elv.sh/
BSD 2-Clause "Simplified" License
5.53k stars 297 forks source link

public versus private module functions #1683

Open krader1961 opened 1 year ago

krader1961 commented 1 year ago

The epm module distinguishes public, versus private, functions by prefixing the latter with -. The problem is that the - prefix convention means the function is experimental and subject to change. Not that it is private. Such functions still appear in the command completion output. Such as when typing epm: then Tab:

~> epm:-debug
 COMPLETING command
epm:-debug               epm:-merge                   epm:-tilde-expand         epm:installed     epm:re:
epm:-domain-config       epm:-package-domain          epm:-uninstall-package    epm:is-installed  epm:str:
epm:-domain-config-file  epm:-package-metadata-file   epm:-warn                 epm:list          epm:uninstall
epm:-error               epm:-package-method          epm:-write-domain-config  epm:metadata      epm:upgrade
epm:-first-upper         epm:-package-op              epm:dest                  epm:platform:
epm:-info                epm:-package-without-domain  epm:install               epm:query

Perhaps the command completion logic should ignore commands with a - prefix. Adding a mechanism for Elvish modules to explicitly document their external API is another solution but that is significantly more complicated.

nichtsundniemand commented 12 months ago

How about a pattern like this:

# file: public.elv
use ./private

fn public {
    echo "I am not as shy as THAT guy!"
    echo "THAT guy:" (private:private)
}

del private:
# file: private.elv
fn private {
    put "Don't look at me!"
}

This results in the following behaviour:

~> use ./public
~> keys $public:
▶ public~
~> public:public
I am not as shy as THAT guy!
THAT guy: Don't look at me!