--- /dev/null
+package Newslash::Command;
+use Mojo::Base 'Mojolicious::Command';
+use List::Util qw(all);
+
+has experimental => 0;
+has danger => 0;
+
+
+sub check_force_option {
+ my ($self, $args) = @_;
+
+ if ($self->experimental) {
+ my $mode = $self->app->mode;
+ if (!$mode || $mode ne "test") {
+ if (all { $_ !~ /^\s*-f\s*$/ } @$args) {
+ $self->app->log->error("This command is experimental, so needs '-f' option under '$mode' mode.");
+ return;
+ }
+ @$args = grep { $_ !~ /^\s*-f\s*$/ } @$args;
+ }
+ }
+
+ if ($self->danger) {
+ if (any { $_ !~ /^\s*-f\s*$/ } @$args) {
+ $self->app->log->error("This command is dangerous, so needs '-f' option.");
+ return;
+ }
+ @$args = grep { $_ !~ /^\s*-f\s*$/ } @$args;
+ }
+
+ return 1;
+}
+
+1;
+
+=encoding utf8
+
+=head1 NAME
+
+Newslash::Command - newslash administer command base class
+
+=head1 METHODS
+
+L<Newslash::Command> inherits all methods from
+L<Mojolicious::Command> and implements the following new ones.
+
+=head2 check_options
+
+ $daemon->run(@ARGV);
+
+Run this command.
+
+=head1 SEE ALSO
+
+L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>.
+
+=cut
package Newslash::Command::useradd;
-use Mojo::Base 'Mojolicious::Command';
+use Mojo::Base 'Newslash::Command';
use Mojo::Util 'getopt';
use Data::Dumper;
has description => 'Add new user';
-#has usage => sub { shift->extract_usage };
+has usage => sub { shift->extract_usage };
+
+has experimental => 1;
+has danger => 0;
sub run {
my ($self, @args) = @_;
- my $app = $self->app;
+ return if !$self->check_force_option(\@args);
+ my $app = $self->app;
my $seclev = 1;
my $author = 0;
my $password = "";
package Newslash::Command::usermod;
-use Mojo::Base 'Mojolicious::Command';
+use Mojo::Base 'Newslash::Command';
use Mojo::Util 'getopt';
use Data::Dumper;
has description => 'Change user properties';
-#has usage => sub { shift->extract_usage };
+has usage => sub { shift->extract_usage };
+
+has experimental => 1;
+has danger => 0;
sub run {
my ($self, @args) = @_;
- my $app = $self->app;
+ return if !$self->check_force_option(\@args);
+ my $app = $self->app;
my $seclev;
my $author;
my $password;