aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2020-07-04 13:49:52 +0200
committerPatrick Spek <p.spek@tyil.nl>2020-07-04 13:49:52 +0200
commit292ae61ff53ed9b215110ec9ff55cee655a03a8c (patch)
treee9e3ae2afff3e9dfa456a568b20a187a0fcded41
parent6e2122b3801194ba82cab1f1063b86755207a2fc (diff)
downloadDist::Maker-292ae61ff53ed9b215110ec9ff55cee655a03a8c.tar.gz
Dist::Maker-292ae61ff53ed9b215110ec9ff55cee655a03a8c.tar.bz2
Add dedication sub for CLI initialization
-rwxr-xr-xbin/rakumod4
-rw-r--r--lib/App/Rakumod.rakumod66
-rw-r--r--lib/App/Rakumod/Bin.rakumod61
-rw-r--r--lib/App/Rakumod/Config.rakumod2
-rw-r--r--lib/App/Rakumod/Util.rakumod8
5 files changed, 68 insertions, 73 deletions
diff --git a/bin/rakumod b/bin/rakumod
index 7bcdf36..05057a3 100755
--- a/bin/rakumod
+++ b/bin/rakumod
@@ -2,10 +2,6 @@
use v6.d;
-my %*SUB-MAIN-OPTS =
- :named-anywhere,
-;
-
use App::Rakumod::Bin;
=begin pod
diff --git a/lib/App/Rakumod.rakumod b/lib/App/Rakumod.rakumod
index 46fbfbb..7c51d16 100644
--- a/lib/App/Rakumod.rakumod
+++ b/lib/App/Rakumod.rakumod
@@ -4,45 +4,43 @@ use v6.d;
use Config;
use IO::Path::XDG;
+use Log;
unit module App::Rakumod;
-my Config $config .= new.read: {
- main => {
- quiet => False,
- template-warnings => True,
- },
- add => {
- prepend-license-lines => '',
- },
- depend => {
- zef-install => False,
- },
- new => {
- path => $*HOME,
- },
-};
-
-sub dm-config-load () is export
-{
- my $file = xdg-config-home.add('rdm/config.toml');
-
- $config .= read($file.absolute) if $file.e;
-
- return;
-}
-
-multi sub dm-config (
- --> Associative
-) is export {
- $config.get;
-}
+our $config;
-multi sub dm-config (
- Str:D $key,
- --> Any
+#| Initialize the CLI application.
+sub rakumod-cli-init (
) is export {
- $config.get($key);
+ if (%*ENV<RAKU_LOG_CLASS>:exists) {
+ $Log::instance = (require ::(%*ENV<RAKU_LOG_CLASS>)).new;
+ $Log::instance.add-output($*OUT, %*ENV<RAKU_LOG_LEVEL> // Log::Level::Info);
+ }
+
+ .debug('Setting SUB-MAIN-OPTS') with $Log::instance;
+
+ my %*SUB-MAIN-OPTS =
+ :named-anywhere,
+ ;
+
+ .info('Initializing $config') with $Log::instance;
+
+ $config //= Config.new({
+ main => {
+ quiet => False,
+ template-warnings => True,
+ },
+ add => {
+ prepend-license-lines => '',
+ },
+ depend => {
+ zef-install => False,
+ },
+ new => {
+ path => $*HOME,
+ },
+ }, :name<rakumod>);
}
=begin pod
diff --git a/lib/App/Rakumod/Bin.rakumod b/lib/App/Rakumod/Bin.rakumod
index c291540..ec69fe9 100644
--- a/lib/App/Rakumod/Bin.rakumod
+++ b/lib/App/Rakumod/Bin.rakumod
@@ -4,6 +4,7 @@ use v6.d;
use IO::Path::XDG;
use JSON::Fast;
+use Log;
use Template::Mustache;
use App::Rakumod::Commands::Add;
@@ -37,9 +38,9 @@ multi sub MAIN (
}
}
- dm-config-load;
+ rakumod-cli-init;
- my $meta-file = dm-scour('META6.json', $*CWD);
+ my $meta-file = rakumod-scour('META6.json', $*CWD);
if (!$meta-file) {
X::App::Rakumod::NoDistribution.new(
@@ -49,7 +50,7 @@ multi sub MAIN (
my %meta = from-json($meta-file.slurp);
- if (!$provide) { $provide = dm-prompt('Unit name') }
+ if (!$provide) { $provide = rakumod-prompt('Unit name') }
if (%meta<provides>.keys ∋ $provide) {
X::App::Rakumod::DuplicateProvide.new(
@@ -68,16 +69,16 @@ multi sub MAIN (
}
;
- with (dm-template('provide.raku')) -> $template {
+ with (rakumod-template('provide.raku')) -> $template {
my $body;
- with (dm-template("licenses/{%meta<license>.fc}-short.txt")) {
- my $license = dm-template-render(
+ with (rakumod-template("licenses/{%meta<license>.fc}-short.txt")) {
+ my $license = rakumod-template-render(
$_.slurp,
%variables,
).trim;
- if (dm-config('add.prepend-license-lines')) -> $prepend {
+ if ($App::Rakumod::config.get('add.prepend-license-lines')) -> $prepend {
$license = $license
.lines
.map(sub ($line) {
@@ -90,26 +91,26 @@ multi sub MAIN (
%variables<license> = $license;
} else {
- note $_.exception.message if dm-config('main.template-warnings');
+ note $_.exception.message if $App::Rakumod::config.get('main.template-warnings');
}
if ($kind) {
- with (dm-template("kinds/$kind.raku")) {
- $body = dm-template-render(
+ with (rakumod-template("kinds/$kind.raku")) {
+ $body = rakumod-template-render(
$_.slurp,
%variables,
);
} else {
- note $_.exception.message if dm-config('main.template-warnings');
+ note $_.exception.message if $App::Rakumod::config.get('main.template-warnings');
}
}
- $contents = dm-template-render($template.slurp, %(
+ $contents = rakumod-template-render($template.slurp, %(
|%variables,
body => $body.?trim // '# TODO',
));
} else {
- note $_.exception.message if dm-config('main.template-warnings');
+ note $_.exception.message if $App::Rakumod::config.get('main.template-warnings');
}
my $file = dist-maker-add(
@@ -119,7 +120,7 @@ multi sub MAIN (
:!sanity-checks
);
- if (!dm-config('main.quiet')) {
+ if (!$App::Rakumod::config.get('main.quiet')) {
say "Added $file to provide $provide for %meta<name>";
}
}
@@ -138,9 +139,9 @@ multi sub MAIN (
}
}
- dm-config-load;
+ rakumod-cli-init;
- my $meta-file = dm-scour('META6.json', $*CWD);
+ my $meta-file = rakumod-scour('META6.json', $*CWD);
if (!$meta-file) {
X::App::Rakumod::NoDistribution.new(
@@ -150,7 +151,7 @@ multi sub MAIN (
my %meta = from-json($meta-file.slurp);
- if (!$module) { $module = dm-prompt('Dependency name'); }
+ if (!$module) { $module = rakumod-prompt('Dependency name'); }
if (%meta<depends> ∋ $module) {
X::App::Rakumod::DuplicateDependency.new(
@@ -164,11 +165,11 @@ multi sub MAIN (
:!sanity-checks,
);
- if (!dm-config('main.quiet')) {
+ if (!$App::Rakumod::config.get('main.quiet')) {
say "Added $module as dependency for %meta<name>";
}
- if (dm-config('depend.zef-install')) {
+ if ($App::Rakumod::config.get('depend.zef-install')) {
run << zef install "$module" >>;
}
}
@@ -190,10 +191,10 @@ multi sub MAIN (
}
}
- dm-config-load;
+ rakumod-cli-init;
- if (!$name) { $name = dm-prompt('Name'); }
- if (!$path) { $path = dm-prompt('Path', dm-config('new.path')); }
+ if (!$name) { $name = rakumod-prompt('Name'); }
+ if (!$path) { $path = rakumod-prompt('Path', $App::Rakumod::config.get('new.path')); }
my $destination = $path.IO.add($name);
@@ -203,27 +204,27 @@ multi sub MAIN (
).throw;
}
- my $description = dm-prompt('Description', :empty);
- my $license = dm-prompt('License', 'AGPL-3.0-or-later');
+ my $description = rakumod-prompt('Description', :empty);
+ my $license = rakumod-prompt('License', 'AGPL-3.0-or-later');
my ($, %meta) = dist-maker-new(
$name,
$description,
$license,
- [dm-config('new.author') // ''],
+ [$App::Rakumod::config.get('new.author') // ''],
$path.IO,
:!sanity-checks,
);
- if (!dm-config('main.quiet')) {
+ if (!$App::Rakumod::config.get('main.quiet')) {
say "Created skeleton for $name at $destination";
}
# Add readme
- with (dm-template('readme.rakudoc')) {
+ with (rakumod-template('readme.rakudoc')) {
$destination
.add('README.rakudoc')
- .spurt(dm-template-render($_.slurp, {
+ .spurt(rakumod-template-render($_.slurp, {
:%meta
}))
.trim
@@ -232,10 +233,10 @@ multi sub MAIN (
}
# Add license
- with (dm-template("licenses/{%meta<license>.fc}-full.txt")) {
+ with (rakumod-template("licenses/{%meta<license>.fc}-full.txt")) {
$destination
.add('LICENSE.txt')
- .spurt(dm-template-render($_.slurp, {
+ .spurt(rakumod-template-render($_.slurp, {
:%meta,
date => {
year => DateTime.now.year,
diff --git a/lib/App/Rakumod/Config.rakumod b/lib/App/Rakumod/Config.rakumod
index 35c5f9e..bd8641e 100644
--- a/lib/App/Rakumod/Config.rakumod
+++ b/lib/App/Rakumod/Config.rakumod
@@ -8,7 +8,7 @@
=head1 Configuration file location
- $XDG_CONFIG_HOME/rdm/config.toml
+ $XDG_CONFIG_HOME/rakumod/config.toml
The value of C<$XDG_CONFIG_HOME> will default to C<$HOME/.config> if it is not
set in your shell.
diff --git a/lib/App/Rakumod/Util.rakumod b/lib/App/Rakumod/Util.rakumod
index 651ccd7..6e0cbe0 100644
--- a/lib/App/Rakumod/Util.rakumod
+++ b/lib/App/Rakumod/Util.rakumod
@@ -7,7 +7,7 @@ use Template::Mustache;
unit module App::Rakumod::Util;
-sub dm-prompt (
+sub rakumod-prompt (
Str:D $prompt is copy,
Str() $default = Str,
Bool:D :$empty = False,
@@ -26,7 +26,7 @@ sub dm-prompt (
}
#| Scour a directory upwards for a certain filename
-sub dm-scour (
+sub rakumod-scour (
Str:D $filename,
IO::Path:D $directory,
--> IO::Path
@@ -41,7 +41,7 @@ sub dm-scour (
}
#| Get the location of a template.
-sub dm-template (
+sub rakumod-template (
Str:D $name,
--> IO::Path
) is export {
@@ -59,7 +59,7 @@ sub dm-template (
fail("No template found for $name, have you created a template file at $user-template?");
}
-sub dm-template-render (
+sub rakumod-template-render (
Str:D $template,
%context,
--> Str