OSDN Git Service

Web: add "subcommand" attribute
authorhylom <hylom@users.sourceforge.jp>
Thu, 27 Sep 2018 11:54:31 +0000 (20:54 +0900)
committerhylom <hylom@users.sourceforge.jp>
Thu, 27 Sep 2018 11:54:31 +0000 (20:54 +0900)
src/newslash_web/lib/Newslash/Web.pm

index 9d13d11..d9da483 100644 (file)
@@ -4,11 +4,16 @@ use Mojo::Util qw(dumper);
 use List::Util qw(any);
 
 use constant CONFIG_FILE => '/etc/newslash/newslash.conf';
+has subcommand => "";
 
 # This method will run once at server start
 sub startup {
     my $app = shift;
 
+    if ($ARGV[0]) {
+        $app->subcommand($ARGV[0]);
+    }
+
     # add commands in Newslash::Command
     push @{$app->commands->namespaces}, 'Newslash::Command';
 
@@ -18,7 +23,7 @@ sub startup {
         $app->plugin('Newslash::Plugin::YAMLConfig', file => CONFIG_FILE);
     }
     else {
-       if ($ARGV[0] && $ARGV[0] eq "configdump") {
+       if ($app->subcommand eq "configdump") {
            $app->plugin('Newslash::Plugin::YAMLConfig', default => {});
        }
        else {
@@ -97,10 +102,10 @@ sub startup {
 
     # check if 'maintenance' mode
     my $maintenance_mode = 0;
-    if (!$ARGV[0]
-       || any { $ARGV[0] eq $_ } qw[configdump configimport databaseinit
-                                    testdatainsert useradd usermod
-                                  ]) {
+    if (!$app->subcommand
+        || any { $app->subcommand eq $_ } qw[configdump configimport databaseinit
+                                             testdatainsert useradd usermod
+                                           ]) {
        $maintenance_mode = 1;
     }