sinclairtarget / um

Create and maintain your own man pages so you can remember how to do stuff
MIT License
1.8k stars 42 forks source link

Use Etc.getpwuid.name instead of Etc.getlogin #31

Open b-ggs opened 4 years ago

b-ggs commented 4 years ago

This fix is specifically for running um inside a Docker container.

For some reason Etc.getlogin returns nil when inside a Docker container. I'm not sure of the reason why that's so, but some light searching pointed to recommendations to use Etc.getpwuid instead of Etc.getlogin anyway. (https://www.rubydoc.info/stdlib/etc/Etc.getlogin)

Reproduction steps:

Dockerfile

FROM ruby:2.6.5-buster

RUN git clone https://github.com/sinclairtarget/um.git \
  && cd um \
  && gem build *.gemspec \
  && gem install um*.gem

CMD ["um", "list"] 

Building and running that produces this output:

/usr/local/bundle/gems/um-4.2.0/lib/um/umconfig.rb:113:in `+': no implicit conversion of nil into String (TypeError)
        from /usr/local/bundle/gems/um-4.2.0/lib/um/umconfig.rb:113:in `write_pages_directory'
        from /usr/local/bundle/gems/um-4.2.0/lib/um/umconfig.rb:78:in `source'
        from /usr/local/bundle/gems/um-4.2.0/libexec/um-list.rb:18:in `<main>'

With patch:

Dockerfile

FROM ruby:2.6.5-buster

RUN git clone --single-branch --branch b-ggs/getpwuid https://github.com/b-ggs/um.git \
  && cd um \
  && gem build *.gemspec \
  && gem install um*.gem

CMD ["um", "list"]

Now, running that presents the expected output:

No pages found for topic "shell."