bluto

Release package and announcement generator
Info | Log | Files | Refs | README | LICENSE

commit 5414968a06d9edba0866659e7b6dbd99f9753ee1
parent 507f82ddcbb6c812d5d6e83ebddec653d919f1ec
Author: lash <dev@holbrook.no>
Date:   Tue,  1 Oct 2024 02:29:10 +0100

Implement bluto-gen with refactored args, envs

Diffstat:
MBluto/Cmd.pm | 40++++++++++++++++++++++++++++++++++++----
Mbluto-boot | 65++++++++++++++++++++++++-----------------------------------------
Mbluto-gen | 80+++++++++++--------------------------------------------------------------------
Mbluto.pl | 70+++++++++++++++-------------------------------------------------------
4 files changed, 86 insertions(+), 169 deletions(-)

diff --git a/Bluto/Cmd.pm b/Bluto/Cmd.pm @@ -4,6 +4,8 @@ use Getopt::Long qw/ :config auto_help /; use Cwd qw/ getcwd abs_path /; use File::Spec; use File::Path qw/make_path/; +use File::Copy; +use Digest::SHA; use Bluto::SemVer; use YAML::Tiny; @@ -44,7 +46,7 @@ sub register_param { push(@opts_x, $switch_long . ':' . $switch_typ); push(@opts_x, \$env{$env_k}); } - if (defined $switch_long) { + if (defined $switch_short) { push(@opts_x, $switch_short . ':' . $switch_typ); push(@opts_x, \$env{$env_k}); } @@ -87,16 +89,46 @@ sub get_param { return $env{$k}; } +sub get_version { + if (defined $env{version}) { + $env{version} = SemVer->new($env{version}); + } + return $env{version}; +} + sub base_config_path { return File::Spec->catfile($env{src_dir}, 'bluto.yml'); } sub release_config_path { if (!defined $env{version}) { - error("release config path does not exist, version not set"); - return undef; + croak("release config path does not exist, version not set"); + } + return File::Spec->catfile($env{src_dir}, $env{version} . '.yml'); +} + +sub base_config { + my $fn = base_config_path(); + my $yi = YAML::Tiny->read($fn); + return $yi->[0]; +} + +sub process_changelog { + my $copy = shift; + + if (!defined $env{changelog_file}) { + croak("changelog file missing"); + } + + my $h = Digest::SHA->new('sha256'); + $h->addfile($env{changelog_file}); + my $z = $h->hexdigest; + debug('calculated sha256 ' . $z . ' for changelog ' . $env{changelog_file}); + if ($copy) { + my $fp = File::Spec->catfile($env{src_dir}, 'CHANGELOG.' . $env{version}); + copy($env{changelog_file}, $fp); } - return File::Spec->catfile($env{src_dir}, '.yml'); + return $z; } 1; diff --git a/bluto-boot b/bluto-boot @@ -4,54 +4,37 @@ use v5.10.1; use warnings; use strict; -use Getopt::Long qw/ :config auto_help /; -use Cwd qw/ getcwd abs_path /; -use File::Spec; -use File::Path qw/make_path/; use File::Basename qw/ dirname /; - +use Cwd qw/ getcwd abs_path /; use lib (dirname(abs_path($0))); -use YAML::Tiny; +use Bluto::Cmd; +#Bluto::Cmd::register_param("version", undef, "version", undef); +Bluto::Cmd::register_param("name", undef, "name", undef); +Bluto::Cmd::register_param("summary", undef, "summary", undef); +my $usr = $ENV{LOGNAME} || $ENV{USER} || getpwuid($<); +Bluto::Cmd::register_param("maintainer", $usr, undef, undef); -sub help() { - print("$0\n\nwould have shown help...\n"); - exit 0; -} - -my %env_sub = ( - name => "", - summary => "", - maintainer => $ENV{LOGNAME} || $ENV{USER} || getpwuid($<), -); +Bluto::Cmd::process_param(); -my $force_version = undef; -my $loglevel = 0; -my $force_help = 0; -my %env = ( - src_dir => File::Spec->catfile(getcwd, '.bluto'), - changelog_file => undef, - version => undef, - loglevel => undef, -); -GetOptions( - 'd:s', \$env{src_dir}, - 'name:s', \$env_sub{name}, - 'summary:s', \$env_sub{summary}, - 'v+', \$loglevel, - 'h+', \$force_help, - 'help+', \$force_help, -); +#my $v = Bluto::Cmd::get_param("version"); +#if (!defined $v) { +# Bluto::Cmd::croak($v); +#} -my $slug = lc($env_sub{name}); -$slug =~ y/ /_/; -$slug =~ s/[^a-zA-Z0-9_]//g; +my $name = Bluto::Cmd::get_param('name'); +my $slug; +if (defined $name) { + my $slug = lc($name); + $slug =~ y/ /_/; + $slug =~ s/[^a-zA-Z0-9_]//g; +} my $yc = { - name => $env_sub{name}, + name => $name, slug => $slug, - summary => $env_sub{summary}, + summary => Bluto::Cmd::get_param('summary'), license => "", copyright => "", tech => "", @@ -80,13 +63,13 @@ my $yc = { pgp => "", }, maintainer => { - name => $env_sub{maintainer}, + name => Bluto::Cmd::get_param('maintainer'), email => "", pgp => "", }, }; -make_path($env{src_dir}); my $yo = YAML::Tiny->new($yc); -my $fn = File::Spec->catfile($env{src_dir}, 'bluto.yml'); +#my $fn = File::Spec->catfile($env{src_dir}, 'bluto.yml'); +my $fn = Bluto::Cmd::base_config_path(); $yo->write($fn); diff --git a/bluto-gen b/bluto-gen @@ -4,90 +4,32 @@ use v5.10.1; use warnings; use strict; -use Getopt::Long qw/ :config auto_help /; use File::Basename qw/ dirname /; -use File::Spec; -use File::Copy; use Cwd qw/ getcwd abs_path /; use lib (dirname(abs_path($0))); -use Digest::SHA; -use SemVer; -use YAML::Tiny; +use Bluto::Cmd; -use Bluto::Log qw/debug/; +Bluto::Cmd::register_param("version", undef, "version", undef); +Bluto::Cmd::register_param("changelog_file", undef, undef, "f"); -# TODO: export to perl modules +Bluto::Cmd::process_param(); - -sub croak { - die(shift); -} - -sub help() { - print("$0\n\nwould have shown help...\n"); - exit 0; -} - -my $force_version = undef; -my $loglevel = 0; -my $force_help = 0; -my %env = ( - src_dir => File::Spec->catfile(getcwd, '.bluto'), - changelog_file => undef, - version => undef, - loglevel => undef, -); -GetOptions( - 'd:s', \$env{src_dir}, - 'f:s', \$env{changelog_file}, - 'v+', \$loglevel, - 'h+', \$force_help, - 'help+', \$force_help, - 'version=s', \$force_version, -); - -if ($force_help > 0) { - help; +my $version = Bluto::Cmd::get_version(); +if (!defined $version) { + Bluto::Cmd::croak("version missing"); } -foreach my $k (keys %env ) { - if (defined $env{$k}) { - $env{$k} = abs_path($env{$k}); - } -} - -if (defined $force_version) { - $env{version} = SemVer->new($force_version); -} - -my $fn = File::Spec->catfile($env{src_dir}, 'bluto.yml'); -my $yi = YAML::Tiny->read($fn); my @contributors; -my $yd = $yi->[0]; +my $yd = Bluto::Cmd::base_config(); my $yv = { - changelog => 'sha256:' . process_changelog(\%env, 1), + changelog => 'sha256:' . Bluto::Cmd::process_changelog(1), author => $yd->{author}->{name}, maintainer => $yd->{maintainer}->{name}, contributors => \@contributors, }; + my $yo = YAML::Tiny->new($yv); -$fn = File::Spec->catfile($env{src_dir}, $env{version} . '.yml'); +my $fn = Bluto::Cmd::release_config_path(); $yo->write($fn); - - -sub process_changelog { - my $env = shift; - my $copy = shift; - - my $h = Digest::SHA->new('sha256'); - $h->addfile($env->{changelog_file}); - my $z = $h->hexdigest; - debug('calculated sha256 ' . $z . ' for changelog ' . $env->{changelog_file}); - if ($copy) { - my $fp = File::Spec->catfile($env->{src_dir}, 'CHANGELOG.' . $env->{version}); - copy($env->{changelog_file}, $fp); - } - return $z; -} diff --git a/bluto.pl b/bluto.pl @@ -10,66 +10,26 @@ use lib (dirname(abs_path($0))); use Bluto::Cmd; -#Bluto::Cmd::register_param("version", undef, "version", undef); -Bluto::Cmd::register_param("name", undef, "name", undef); -Bluto::Cmd::register_param("summary", undef, "summary", undef); -my $usr = $ENV{LOGNAME} || $ENV{USER} || getpwuid($<); -Bluto::Cmd::register_param("maintainer", $usr, undef, undef); +Bluto::Cmd::register_param("version", undef, "version", undef); +Bluto::Cmd::register_param("changelog_file", undef, undef, "f"); Bluto::Cmd::process_param(); -#my $v = Bluto::Cmd::get_param("version"); -#if (!defined $v) { -# Bluto::Cmd::croak($v); -#} - -my $name = Bluto::Cmd::get_param('name'); -my $slug; -if (defined $name) { - my $slug = lc(); - $slug =~ y/ /_/; - $slug =~ s/[^a-zA-Z0-9_]//g; +my $version = Bluto::Cmd::get_version(); +if (!defined $version) { + Bluto::Cmd::croak("version missing"); } -my $yc = { - name => $name, - slug => $slug, - summary => Bluto::Cmd::get_param('summary'), - license => "", - copyright => "", - tech => "", - vcs => { - tag_prefix => "v", - }, - sign => { - rsa => "", - ed22519 => "", - secp256k1 => "", - }, - fund => { - btc => "", - eth => "", - monero => "", - }, - locate => { - www => [], - rel => [], - vcs => [], - tgzbase => [], - }, - author => { - name => "", - email => "", - pgp => "", - }, - maintainer => { - name => Bluto::Cmd::get_param('maintainer'), - email => "", - pgp => "", - }, + +my @contributors; +my $yd = Bluto::Cmd::base_config(); +my $yv = { + changelog => 'sha256:' . Bluto::Cmd::process_changelog(1), + author => $yd->{author}->{name}, + maintainer => $yd->{maintainer}->{name}, + contributors => \@contributors, }; -my $yo = YAML::Tiny->new($yc); -#my $fn = File::Spec->catfile($env{src_dir}, 'bluto.yml'); -my $fn = Bluto::Cmd::base_config_path(); +my $yo = YAML::Tiny->new($yv); +my $fn = Bluto::Cmd::release_config_path(); $yo->write($fn);