nitpackage: check existence of README.md files
authorAlexandre Terrasa <alexandre@moz-code.org>
Thu, 10 May 2018 19:13:35 +0000 (15:13 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Thu, 17 May 2018 21:43:10 +0000 (17:43 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

share/man/nitpackage.md
src/model/mpackage.nit
src/nitpackage.nit

index 122ce85..4a4da91 100644 (file)
@@ -66,6 +66,9 @@ Check manpages files.
 ### `--gen-man`
 Generate manpages files.
 
+### `--check-readme`
+Check README.md files.
+
 ### `-f`, `--force`
 Force update of existing files.
 
index 3157233..1cdde49 100644 (file)
@@ -92,6 +92,21 @@ class MPackage
                if ini_path == null then return false
                return ini_path.file_exists
        end
+
+       # The path to `self` README.md
+       fun readme_path: nullable String do
+               var path = package_path
+               if path == null then return null
+               if not is_expanded then return null
+               return path / "README.md"
+       end
+
+       # Does `self` have a README.md file?
+       fun has_readme: Bool do
+               var readme_path = self.readme_path
+               if readme_path == null then return false
+               return readme_path.file_exists
+       end
 end
 
 # A group of modules in a package
index bb6fb42..d9f4831 100644 (file)
@@ -19,6 +19,10 @@ import frontend
 import doc::commands::commands_main
 
 redef class ToolContext
+
+       # nitpackage phase
+       var nitpackage_phase: Phase = new NitPackagePhase(self, null)
+
        # --expand
        var opt_expand = new OptionBool("Move singleton packages to their own directory", "--expand")
 
@@ -37,21 +41,22 @@ redef class ToolContext
        # --gen-makefile
        var opt_gen_makefile = new OptionBool("Generate Makefile files", "--gen-makefile")
 
-       # nitpackage phase
-       var nitpackage_phase: Phase = new NitPackagePhase(self, null)
-
        # --check-man
        var opt_check_man = new OptionBool("Check manpages files", "--check-man")
 
        # --gen-man
        var opt_gen_man = new OptionBool("Generate manpages files", "--gen-man")
 
+       # --check-readme
+       var opt_check_readme = new OptionBool("Check README.md files", "--check-readme")
+
        redef init do
                super
                option_context.add_option(opt_expand, opt_force)
                option_context.add_option(opt_check_ini, opt_gen_ini)
                option_context.add_option(opt_check_makefile, opt_gen_makefile)
                option_context.add_option(opt_check_man, opt_gen_man)
+               option_context.add_option(opt_check_readme)
        end
 end
 
@@ -87,6 +92,12 @@ private class NitPackagePhase
                                continue
                        end
 
+                       # Check README.md
+                       if toolcontext.opt_check_readme.value then
+                               mpackage.check_readme(toolcontext)
+                               continue
+                       end
+
                        # Expand packages
                        if toolcontext.opt_expand.value and not mpackage.is_expanded then
                                var path = mpackage.expand
@@ -417,6 +428,15 @@ redef class MPackage
                        mmodule.gen_man(toolcontext)
                end
        end
+
+       # README
+
+       private fun check_readme(toolcontext: ToolContext) do
+               if not has_readme then
+                       toolcontext.error(location, "No `README.md` file for `{name}`")
+                       return
+               end
+       end
 end
 
 redef class MModule