@@ -49,93 +49,77 @@ public function __construct(BuildConfig $buildConfig)
49
49
50
50
protected function configure ()
51
51
{
52
- parent ::configure ();
53
-
54
52
$ this
55
53
->addArgument ('source-dir ' , InputArgument::OPTIONAL , 'RST files Source directory ' , getcwd ())
56
- ->addArgument ('output-dir ' , InputArgument::OPTIONAL , 'HTML files output directory ' )
57
- ->addOption (
58
- 'parse-sub-path ' ,
59
- null ,
60
- InputOption::VALUE_OPTIONAL ,
61
- 'Parse only given sub directory and combine it into a single file (directory relative from source-dir) ' ,
62
- ''
63
- )
64
- ->addOption (
65
- 'output-json ' ,
66
- null ,
67
- InputOption::VALUE_NONE ,
68
- 'If provided, .fjson metadata files will be written '
69
- )
70
- ->addOption (
71
- 'disable-cache ' ,
72
- null ,
73
- InputOption::VALUE_NONE ,
74
- 'If provided, caching meta will be disabled '
75
- )
76
- ->addOption (
77
- 'save-errors ' ,
78
- null ,
79
- InputOption::VALUE_REQUIRED ,
80
- 'Path where any errors should be saved '
81
- )
82
- ->addOption (
83
- 'error-output-format ' ,
84
- null ,
85
- InputOption::VALUE_REQUIRED ,
86
- 'The output format for errors on std out ' ,
87
- Configuration::OUTPUT_FORMAT_CONSOLE
88
- )
89
- ->addOption (
90
- 'no-theme ' ,
91
- null ,
92
- InputOption::VALUE_NONE ,
93
- 'Use the default theme instead of the styled one '
94
- )
95
- ->addOption (
96
- 'fail-on-errors ' ,
97
- null ,
98
- InputOption::VALUE_NONE ,
99
- 'Return a non-zero code if there are errors/warnings '
100
- )
54
+ ->addArgument ('output-dir ' , InputArgument::OPTIONAL , 'HTML files output directory ' , rtrim (getcwd (), '/ ' ).'/html ' )
55
+
56
+ ->addOption ('images-dir ' , null , InputOption::VALUE_REQUIRED , 'Images files output directory ' )
57
+ ->addOption ('config ' , null , InputOption::VALUE_REQUIRED , 'Path to the config file ' )
58
+
59
+ ->addOption ('disable-cache ' , null , InputOption::VALUE_NONE , 'If provided, caching meta will be disabled ' )
60
+ ->addOption ('parse-sub-path ' , null , InputOption::VALUE_REQUIRED , 'Parse only given sub directory and combine it into a single file (directory relative from source-dir) ' , '' )
61
+ ->addOption ('output-json ' , null , InputOption::VALUE_NONE , 'If provided, .fjson metadata files will be written ' )
62
+ ->addOption ('no-theme ' , null , InputOption::VALUE_NONE , 'Use the default theme instead of the styled one ' )
63
+
64
+ ->addOption ('fail-on-errors ' , null , InputOption::VALUE_NONE , 'Return a non-zero code if there are errors/warnings ' )
65
+ ->addOption ('save-errors ' , null , InputOption::VALUE_REQUIRED , 'Path where any errors should be saved ' )
66
+ ->addOption ('error-output-format ' , null , InputOption::VALUE_REQUIRED , 'The output format for errors on std out ' , Configuration::OUTPUT_FORMAT_CONSOLE )
101
67
;
102
68
}
103
69
104
70
protected function initialize (InputInterface $ input , OutputInterface $ output )
105
71
{
72
+ $ filesystem = new Filesystem ();
106
73
$ this ->io = new SymfonyStyle ($ input , $ output );
107
74
75
+ if ($ input ->getOption ('disable-cache ' )) {
76
+ $ this ->buildConfig ->disableBuildCache ();
77
+ }
78
+
108
79
$ sourceDir = $ input ->getArgument ('source-dir ' );
109
- if (!file_exists ($ sourceDir )) {
80
+ if (!$ filesystem -> exists ($ sourceDir )) {
110
81
throw new \InvalidArgumentException (sprintf ('RST source directory "%s" does not exist ' , $ sourceDir ));
111
82
}
112
83
$ this ->buildConfig ->setContentDir ($ sourceDir );
113
84
114
- $ filesystem = new Filesystem ();
115
- $ htmlOutputDir = $ input ->getArgument ('output-dir ' ) ?? rtrim (getcwd (), '/ ' ).'/html ' ;
116
- if ($ input ->getOption ('disable-cache ' ) && $ filesystem ->exists ($ htmlOutputDir )) {
85
+ $ htmlOutputDir = $ input ->getArgument ('output-dir ' );
86
+ if (!$ this ->buildConfig ->isBuildCacheEnabled () && $ filesystem ->exists ($ htmlOutputDir )) {
117
87
$ filesystem ->remove ($ htmlOutputDir );
118
88
}
119
89
$ filesystem ->mkdir ($ htmlOutputDir );
120
90
$ this ->buildConfig ->setOutputDir ($ htmlOutputDir );
121
91
92
+ $ imgOutputDir = $ input ->getOption ('images-dir ' );
93
+ if ($ imgOutputDir ) {
94
+ if (!$ this ->buildConfig ->isBuildCacheEnabled () && $ filesystem ->exists ($ imgOutputDir )) {
95
+ $ filesystem ->remove ($ imgOutputDir );
96
+ }
97
+ $ this ->buildConfig ->setImageDir ($ imgOutputDir );
98
+ }
99
+
122
100
$ parseSubPath = $ input ->getOption ('parse-sub-path ' );
123
101
if ($ parseSubPath && $ input ->getOption ('output-json ' )) {
124
102
throw new \InvalidArgumentException ('Cannot pass both --parse-sub-path and --output-json options. ' );
125
103
}
126
- if (!file_exists ($ sourceDir .'/ ' .$ parseSubPath )) {
104
+ if (!$ filesystem -> exists ($ sourceDir .'/ ' .$ parseSubPath )) {
127
105
throw new \InvalidArgumentException (sprintf ('Given "parse-sub-path" directory "%s" does not exist ' , $ parseSubPath ));
128
106
}
129
107
$ this ->buildConfig ->setSubdirectoryToBuild ($ parseSubPath );
130
108
131
- if ($ input ->getOption ('disable-cache ' )) {
132
- $ this ->buildConfig ->disableBuildCache ();
109
+ $ this ->buildConfig ->setTheme ($ input ->getOption ('no-theme ' ) ? Configuration::THEME_DEFAULT : 'rtd ' );
110
+
111
+ $ configFileParser = new ConfigFileParser ($ this ->buildConfig );
112
+ $ configPath = $ input ->getOption ('config ' );
113
+ if ($ configPath && !file_exists ($ configPath )) {
114
+ throw new \RuntimeException (sprintf ('No config file present at <info>%s</info> ' , $ configPath ));
133
115
}
134
116
135
- $ this ->buildConfig ->setTheme ($ input ->getOption ('no-theme ' ) ? Configuration::THEME_DEFAULT : 'rtd ' );
117
+ if (!$ configPath && !file_exists ($ configPath = $ sourceDir .'/docs.json ' )) {
118
+ return ;
119
+ }
136
120
137
- $ configFileParser = new ConfigFileParser ( $ this -> buildConfig , $ output );
138
- $ configFileParser ->processConfigFile ($ sourceDir );
121
+ $ this -> io -> writeln ( sprintf ( ' Loading config file: <info>%s</info> ' , $ configPath ) );
122
+ $ configFileParser ->processConfigFile ($ configPath );
139
123
}
140
124
141
125
protected function execute (InputInterface $ input , OutputInterface $ output ): int
@@ -146,6 +130,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
146
130
147
131
$ configuration = $ builder ->getConfiguration ();
148
132
$ configuration ->setOutputFormat ($ input ->getOption ('error-output-format ' ));
133
+ $ configuration ->silentOnError (false );
149
134
$ this ->addProgressListener ($ configuration ->getEventManager ());
150
135
151
136
$ builder ->build (
@@ -184,7 +169,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
184
169
$ this ->io ->success ('Build completed with warnings ' );
185
170
186
171
if ($ input ->getOption ('fail-on-errors ' )) {
187
- return 1 ;
172
+ return Command:: FAILURE ;
188
173
}
189
174
} else {
190
175
$ this ->io ->success ('Build completed successfully! ' );
0 commit comments