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")
# --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
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
var ini_path = ini_path
if ini_path == null then return
- var ini = new ConfigTree(ini_path)
+ var ini = new IniFile.from_file(ini_path)
- ini.check_key(toolcontext, self, "package.name", name)
- ini.check_key(toolcontext, self, "package.desc")
- ini.check_key(toolcontext, self, "package.tags")
+ ini.check_key(ini_path, toolcontext, self, "package.name", name)
+ ini.check_key(ini_path, toolcontext, self, "package.desc")
+ ini.check_key(ini_path, toolcontext, self, "package.tags")
# FIXME since `git reflog --follow` seems bugged
- ini.check_key(toolcontext, self, "package.maintainer")
+ ini.check_key(ini_path, toolcontext, self, "package.maintainer")
# var maint = mpackage.maintainer
# if maint != null then
# ini.check_key(toolcontext, self, "package.maintainer", maint)
# ini.check_key(toolcontext, self, "package.more_contributors", contribs.join(", "))
# end
- ini.check_key(toolcontext, self, "package.license", license)
- ini.check_key(toolcontext, self, "upstream.browse", browse_url)
- ini.check_key(toolcontext, self, "upstream.git", git_url)
- ini.check_key(toolcontext, self, "upstream.git.directory", git_dir)
- ini.check_key(toolcontext, self, "upstream.homepage", homepage_url)
- ini.check_key(toolcontext, self, "upstream.issues", issues_url)
+ ini.check_key(ini_path, toolcontext, self, "package.license", license)
+ ini.check_key(ini_path, toolcontext, self, "upstream.browse", browse_url)
+ ini.check_key(ini_path, toolcontext, self, "upstream.git", git_url)
+ ini.check_key(ini_path, toolcontext, self, "upstream.git.directory", git_dir)
+ ini.check_key(ini_path, toolcontext, self, "upstream.homepage", homepage_url)
+ ini.check_key(ini_path, toolcontext, self, "upstream.issues", issues_url)
- for key in ini.to_map.keys do
+ for key in ini.flatten.keys do
if not allowed_ini_keys.has(key) then
toolcontext.warning(location, "unknown-ini-key",
- "Warning: ignoring unknown `{key}` key in `{ini.ini_file}`")
+ "Warning: ignoring unknown `{key}` key in `{ini_path}`")
end
end
end
private fun gen_ini: String do
var ini_path = self.ini_path.as(not null)
- var ini = new ConfigTree(ini_path)
+ var ini = new IniFile.from_file(ini_path)
ini.update_value("package.name", name)
ini.update_value("package.desc", "")
ini.update_value("upstream.homepage", homepage_url)
ini.update_value("upstream.issues", issues_url)
- ini.save
+ ini.write_to_file(ini_path)
return ini_path
end
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
end
end
-redef class ConfigTree
- private fun check_key(toolcontext: ToolContext, mpackage: MPackage, key: String, value: nullable String) do
+redef class IniFile
+ private fun check_key(ini_file: String, toolcontext: ToolContext, mpackage: MPackage, key: String, value: nullable String) do
if not has_key(key) then
toolcontext.warning(mpackage.location, "missing-ini-key",
"Warning: missing `{key}` key in `{ini_file}`")