ugexe / zef

Raku Module Management
Artistic License 2.0
207 stars 44 forks source link

Provide callable versions of command line functions #241

Open JJ opened 6 years ago

JJ commented 6 years ago

Command line functions are mapped to a multi MAIN in Zef::CLI. In some cases, they provide interesting functionality, and I'm talking about locate, for instance.

Context

In this stackoverflow question, they want to locate something that has been installed. I tried to reproduce the functionality of the code in Zef::CLI and failed, due to usage of global variables and somesuch. I finally opted for running zef externally and processing output.

Expected Behavior

It would be nice to have something like

use Zef::Functions;

my $actual-location-of-file = locate( $file-or-sha1);

Actual Behavior

You need to do zef locate file

niner commented 6 years ago

Please someone post to the stackoverflow question that the simple answer is: don't. Installed distributions are immutable. They must not change and we rely on that and will only more rely on that. The on-disk layout of the a CompUnit::Repository::Installation is undocumented and may change at any time. You must not treat it like a bunch of files. Treat it like an opaque database instead. It's even possible that modules and resources are not even stored in files at all.

The correct solution in the mentioned case is to give the module's user a chance to add some configuration, e.g. from /etc/yourmodule/config.json or ~/.config/yourmodule/config.json or better even, just pass in additional config values to a constructor.

ugexe commented 6 years ago

In the next refactor many things will be available functionally through some sort of Zef::Utils::. https://github.com/ugexe/zef2/tree/master/lib/Zef/Utils was a rough idea of this.


A utility function to return structured data would be ideal, but since you're already parsing the output you can instead do the following ( to avoid shell/run ):

$ perl6 -MZef::CLI -e '&MAIN("locate", "bin/zef");'
$ perl6 -e 'use Zef::CLI; &MAIN("locate", "bin/zef")'
===> From Distribution: zef:ver<0.2.9>:auth<github:ugexe>:api<>
bin/zef => /home/nickl/.rakudobrew/moar-blead-master/install/share/perl6/site/resources/07E90631EAC899CA4F595009BEDECA893C5AB8FE
JJ commented 6 years ago

Thanks!

JJ commented 5 years ago

Are there any plans to have something like this in the current Zef::Utils

tony-o commented 5 years ago

@jj not likely. The functionality and extension may become possible after some work I’m doing to make require xyz:file<> merge symbols correctly but that’s not likely to happen today or tomorrow. You can replicate the functionality in a script by useing Zef stuff in the script