utzig commented on a change in pull request #368: [RFC] Add commands to build and browse man pages URL: https://github.com/apache/mynewt-newt/pull/368#discussion_r374888309
########## File path: newt/man/man.go ########## @@ -0,0 +1,111 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package man + +import ( + "fmt" + "path" + + "mynewt.apache.org/newt/newt/project" + "mynewt.apache.org/newt/newt/repo" + "mynewt.apache.org/newt/util" +) + +const MAN_DOXY_CONF = "man-pages.conf" +const MAN_REL_PATH = "/man" + +func buildDoxyManPages(proj *project.Project, repo *repo.Repo) error { + util.StatusMessage(util.VERBOSITY_DEFAULT, + "Preparing man-pages, running doxygen for \"%s\"\n", repo.Name()) + + doxyCmd := []string{ + "doxygen", + path.Join(repo.Path(), MAN_DOXY_CONF), + } + + env := map[string]string{ + "MANPATH": path.Join(proj.BasePath, MAN_REL_PATH), + "NEWT_PROJ_ROOT": proj.BasePath, + "NEWT_REPO_ROOT": repo.Path(), + } + + util.ShellCommand(doxyCmd, env) + + return nil +} + +func buildManDb(proj *project.Project) error { + util.StatusMessage(util.VERBOSITY_DEFAULT, "Updating man-page index caches") + + manDbCmd := []string{ + "mandb", + } + + env := map[string]string{ + "MANPATH": path.Join(proj.BasePath, MAN_REL_PATH), + } + + util.ShellCommand(manDbCmd, env) + + return nil +} + +func BuildManPages(proj *project.Project) error { + for _, repo := range proj.Repos() { + manPath := path.Join(repo.Path(), MAN_DOXY_CONF) + if util.NodeExist(manPath) { + buildDoxyManPages(proj, repo) + } + } + buildManDb(proj) + + return nil +} + +func RunMan(proj *project.Project, args []string) error { + manCmd := []string{ + "/usr/bin/man", + args[0], + } + + env := map[string]string{ + "MANPATH": path.Join(proj.BasePath, MAN_REL_PATH), + } + + return util.ShellInteractiveCommand(manCmd, env, true) Review comment: > Do you see this behavior, or is it just my environment? Thanks for testing, yes, I totally missed this! It was fixed now. Also added proper error handling, which was missing, and updated the hard-coded `man` binary path to use `exec.LookPath` (because it runs in full screen and needs to started by `os.StartProcess` or some fork like thing!). One feature missing is pruning of existing man pages when a repo goes away, but I am not sure how to do it, maybe just `rm -rf man/`, but doesn't feel like a good thing to do... ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
