/
Lib.pm6
83 lines (69 loc) · 1.39 KB
/
Lib.pm6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#! /usr/bin/env false
use v6.c;
use App::Assixt::Config;
use Config;
use Dist::Helper::Meta;
use Dist::Helper::Template;
class App::Assixt::Commands::Touch::Lib
{
multi method run(
"class",
Str:D $provide,
Config:D :$config,
) {
self.run(
"lib",
$provide,
"class",
:$config,
)
}
multi method run(
"unit",
Str:D $provide,
Config:D :$config,
) {
self.run(
"lib",
$provide,
"unit",
:$config,
)
}
multi method run(
"lib",
Str:D $provide,
Str $type = "lib",
Config:D :$config,
) {
my %meta = get-meta;
my $path = "./lib".IO;
# Deduce the path to create
for $provide.split("::") {
$path = $path.add($_);
}
$path = $path.extension("pm6", parts => 0);
if ($path.e) {
die "File already exists at {$path.absolute}";
}
my $template = "module/";
my %context = %(
perl => %meta<perl>,
vim => template("vim-line/$config<style><indent>", context => $config<style>).trim-trailing,
author => %meta<authors>.join(", "),
version => %meta<version>,
:$provide,
);
given $type {
when "class" { $template ~= "class" }
when "unit" { $template ~= "unit" }
default { $template ~= "lib" }
}
template($template, $path, :%context);
# Update META6.json
%meta<provides>{$provide} = $path.relative;
put-meta(:%meta);
# Inform the user of success
say "Added $provide to {%meta<name>}";
}
}