aboutsummaryrefslogtreecommitdiff
path: root/lib/Dist/Maker/Bin.rakumod
blob: 30c2211e618860b05ad420316e85776f18bc9f62 (plain)
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#! /usr/bin/env false

use v6.d;

use JSON::Fast;

use Dist::Maker::Commands::Depend;
use Dist::Maker::Commands::New;
use Dist::Maker::Exception;
use Dist::Maker::Util;
use Dist::Maker;
use X::Dist::Maker::Clobber;
use X::Dist::Maker::DuplicateDependency;
use X::Dist::Maker::NoDistribution;

unit module Dist::Maker::Bin;

#| Add a dependency.
multi sub MAIN (
	'depend',

	#| The module to add to the dependencies.
	Str $module,
) is export {
	CATCH {
		when Dist::Maker::Exception {
			note $_.message;
			exit $_.code;
		}
	}

	dm-config-load;

	my $meta-file = dm-scour('META6.json', $*CWD);

	if (!$meta-file) {
		X::Dist::Maker::NoDistribution.new(
			path => $*CWD,
		).throw;
	}

	my %meta = from-json($meta-file.slurp);

	if (!$module) { $module = dm-prompt('Dependency name'); }

	if (%meta<depends> (cont) $module) {
		X::Dist::Maker::DuplicateDependency.new(
			:$module
		).throw
	}

	dist-maker-depend(
		$module,
		$meta-file,
		:!sanity-checks,
	);

	if (!dm-config('main.quiet')) {
		say "Added $module as dependency for %meta<name>";
	}

	if (dm-config('depend.zef-install')) {
		run << zef install "$module" >>;
	}
}

#| Create a new module skeleton.
multi sub MAIN (
	'new',

	#| The name of the module.
	Str $name is copy = Str,

	#| The path where the module directory will be created at.
	Str $path is copy = Str,
) is export {
	CATCH {
		when Dist::Maker::Exception {
			note $_.message;
			exit $_.code;
		}
	}

	dm-config-load;

	if (!$name) { $name = dm-prompt('Name'); }
	if (!$path) { $path = dm-prompt('Path', dm-config('new.path')); }

	my $destination = $path.IO.add($name);

	if ($destination.e) {
		X::Dist::Maker::Clobber.new(
			path => $destination.absolute,
		).throw;
	}

	my $description = dm-prompt('Description', :empty);
	my $license = dm-prompt('License', 'AGPL-3.0');

	dist-maker-new(
		$name,
		$description,
		$license,
		$path.IO,
		:!sanity-checks,
	);

	if (!dm-config('main.quiet')) {
		say "Created skeleton for $name at $destination";
	}
}

=begin pod

=NAME    Dist::Maker::Bin
=AUTHOR  Patrick Spek <p.spek@tyil.work>
=VERSION 0.0.0

=head1 Synopsis

=head1 Description

=head1 Examples

=head1 See also

=end pod

# vim: ft=perl6 noet