Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide callable versions of command line functions #241

Open
JJ opened this issue Apr 24, 2018 · 5 comments
Open

Provide callable versions of command line functions #241

JJ opened this issue Apr 24, 2018 · 5 comments

Comments

@JJ
Copy link
Contributor

JJ commented Apr 24, 2018

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
Copy link
Collaborator

niner commented Apr 24, 2018

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
Copy link
Owner

ugexe commented Apr 27, 2018

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
Copy link
Contributor Author

JJ commented Apr 29, 2018 via email

@JJ
Copy link
Contributor Author

JJ commented Feb 15, 2019

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

@tony-o
Copy link
Collaborator

tony-o commented Feb 15, 2019

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants