Finished template for manpage, added --version flag.

This commit is contained in:
Michael Lazar
2015-09-27 18:19:00 -07:00
parent dfc5ddef1a
commit ba71453b7c
6 changed files with 132 additions and 185 deletions

129
rtv.1
View File

@@ -1,102 +1,73 @@
.TH "RTV" "1" "September 2015" "Version 1.5" "Usage and Commands" .TH "RTV" "1" "September 28, 2015" "Version 1.5" "Usage and Commands"
.SH NAME .SH NAME
rtv - Browse Reddit from your terminal RTV - Reddit Terminal Viewer
.SH SYNOPSIS .SH SYNOPSIS
rtv [-h] [-s SUBREDDIT] [-l LINK] [--ascii] [--log FILE] [-u USERNAME] [--non-persistant] [--clear-auth] rtv [\-h] [\-V] [\-s SUBREDDIT] [\-l LINK] [\-\-ascii] [\-\-log FILE] [\-\-non\-persistent] [\-\-clear\-auth]
.SH DESCRIPTION .SH DESCRIPTION
.B Reddit Terminal Viewer Reddit Terminal Viewer is a lightweight browser for www.reddit.com built into a
is a lightweight browser for www.reddit.com built into a
terminal window. terminal window.
.SH OPTIONS .SH OPTIONS
.TP .TP
\fB\-h\fR, \fB\-\-help\fR \fB\-h\fR, \fB\-\-help\fR
show this help message and exit show this help message and exit
.TP .TP
\fB\-s\fR SUBREDDIT \fB\-V\fR, \fB\-\-version\fR
subreddit name show program's version number and exit
.TP .TP
\fB\-l\fR LINK \fB\-s SUBREDDIT\fR
full link to a submission name of the subreddit that will be opened on start
.TP
\fB\-l LINK\fR
full URL of a submission that will be opened on start
.TP .TP
\fB\-\-ascii\fR \fB\-\-ascii\fR
enable ascii\-only mode enable ascii\-only mode
.TP .TP
\fB\-\-log\fR FILE \fB\-\-log FILE\fR
Log HTTP requests log HTTP requests to a file
.PP
.TP
\fB\-\-non\-persistent\fR
Forget all authenticated users when the program exits
.TP
\fB\-\-clear\-auth\fR
Remove any saved OAuth tokens before starting
.SH CONTROLS .SH CONTROLS
RTV has different commands to easily navigate through subreddits and individual submissions. These can all be viewed along with a short description by pressing the \fB?\fR key at any time while running rtv. Navigate between posts by using the arrow keys or vim-style `hjkl` movement.
.PP You can view the full list of commands by pressing the \fB?\fR key inside of the program.
.SH FILES .SH FILES
.TP .TP
All config files can make use of $XDG_CONFIG_HOME which allows you to place them in other places then the given example paths. .BR $XDG_CONFIG_HOME/rtv/rtv.cfg
The configuration file can be used to customize default program settings, see
README.rst for more information.
.TP .TP
~/.config/rtv/rtv.cfg .BR $XDG_CONFIG_HOME/rtv/refresh-token
Personal configuration file. After you login to reddit, your most recent OAuth refresh token will be stored
.TP for future sessions. You can disable this behavior by setting the option
~/.config/rtv/refresh-token \fBpersistent=False\fR in your configuration file.
Session token for OAuth login, if you do not wish to have a persistent login you can set the option \fBpersistent=False\fR in the config file. But some features will not be available. .SH ENVIRONMENT
.SH CONFIG FILE EXAMPLE
.B RTV
has many options that can be set in a configuration file. Here is a simple example configuration.
.nf
[rtv]
# Log file location
log=/tmp/rtv.log
# Default subreddit
subreddit=CollegeBasketball
# Default submission link - will be opened every time the program starts
link=http://www.reddit.com/r/CollegeBasketball/comments/31irjq
# Turn on ascii-only mode and disable all unicode characters
# This may be necessary for compatibility with some terminal browsers
ascii=True
# Enable persistent storage of your authentication token
# This allows you to remain logged in when you restart the program
persistent=True
.SH ENVIROMENT VARIABLES
.B RTV
Supports enviroment variables that can help improve your experience. These options can be set in the current shell. Or placed in your configuration file for your shell of choice. Such as
.IR ~/.bashrc
or
.IR ~/.zshrc
, restarting your session will make these settings persistent for future use of
.B RTV.
.TP .TP
.BR RTV_EDITOR .BR RTV_EDITOR
Setting Specifies which text editor RTV will attempt to use when editing comments and
.IR export posts. RTV will fallback to \fI$EDITOR\fR if the editor is unspecified.
.IR RTV_EDITOR=gedit
will open gedit as your editor when composing comments and replies.
If no editor is set,
.B RTV
will fall back to the environment's default
.IR $EDITOR
, and as an extra fall back nano.
.TP .TP
.BR BROWSER .BR BROWSER
.B RTV Specifies which webbrowser RTV will attempt to use when opening links.
can open links in any browser you wish to use. Most system's will open the default such as Firefox or Chrome. But if you prefer to enjoy a terminal only experience, you can use This can be set to a terminal browser (w3m, lynx, elinks, etc.) for a true
.IR $BROWSER terminal experience. RTV will fallback to the system's default browser.
to set a browser such as w3m, lynx, and elinks. For example w3m would be
.IR export
.IR BROWSER=w3m
.PP
.SH AUTHOR .SH AUTHOR
Written by Johnathan "ShaggyTwoDope" Jenkins <twodopeshaggy@gmail.com> (2015). Man page written by Johnathan "ShaggyTwoDope" Jenkins <twodopeshaggy@gmail.com> (2015).
.SH REPORTING BUGS .SH BUGS
Report bugs to Report bugs to \fIhttps://github.com/michael-lazar/rtv/issues\fR
.I https://github.com/michael-lazar/rtv/issues .SH LICENSE
.SH COPYRIGHT The MIT License (MIT)
Copyright \(co 2015 michael-lazar
License MIT.
.PP .PP
(c) 2015 Michael Lazar

View File

@@ -61,7 +61,7 @@ def main():
try: try:
print('Connecting...') print('Connecting...')
reddit = praw.Reddit(user_agent=AGENT) reddit = praw.Reddit(user_agent=AGENT.format(__version__))
reddit.config.decode_html_entities = False reddit.config.decode_html_entities = False
with curses_session() as stdscr: with curses_session() as stdscr:
oauth = OAuthTool(reddit, stdscr, LoadScreen(stdscr)) oauth = OAuthTool(reddit, stdscr, LoadScreen(stdscr))

View File

@@ -5,7 +5,7 @@ import os
import argparse import argparse
from six.moves import configparser from six.moves import configparser
from . import docs from . import docs, __version__
HOME = os.path.expanduser('~') HOME = os.path.expanduser('~')
XDG_HOME = os.getenv('XDG_CONFIG_HOME', os.path.join(HOME, '.config')) XDG_HOME = os.getenv('XDG_CONFIG_HOME', os.path.join(HOME, '.config'))
@@ -25,12 +25,11 @@ oauth_scope = ['edit', 'history', 'identity', 'mysubreddits', 'privatemessages',
'read', 'report', 'save', 'submit', 'subscribe', 'vote'] 'read', 'report', 'save', 'submit', 'subscribe', 'vote']
def build_parser(): def build_parser():
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
prog='rtv', description=docs.SUMMARY, epilog=docs.CONTROLS+docs.HELP, prog='rtv', description=docs.SUMMARY, epilog=docs.CONTROLS+docs.HELP,
formatter_class=argparse.RawDescriptionHelpFormatter) formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument( parser.add_argument(
'-V', '--version', action='version', version='rtv '+docs.__version__, '-V', '--version', action='version', version='rtv '+__version__,
) )
parser.add_argument( parser.add_argument(
'-s', dest='subreddit', '-s', dest='subreddit',

View File

@@ -1,11 +1,10 @@
from .__version__ import __version__
__all__ = ['AGENT', 'SUMMARY', 'CONTROLS', 'HELP', 'COMMENT_FILE', __all__ = ['AGENT', 'SUMMARY', 'CONTROLS', 'HELP', 'COMMENT_FILE',
'SUBMISSION_FILE', 'COMMENT_EDIT_FILE'] 'SUBMISSION_FILE', 'COMMENT_EDIT_FILE']
AGENT = """\ AGENT = """\
desktop:https://github.com/michael-lazar/rtv:{} (by /u/civilization_phaze_3)\ desktop:https://github.com/michael-lazar/rtv:{version}\
""".format(__version__) (by /u/civilization_phaze_3)\
"""
SUMMARY = """ SUMMARY = """
Reddit Terminal Viewer is a lightweight browser for www.reddit.com built into a Reddit Terminal Viewer is a lightweight browser for www.reddit.com built into a

View File

@@ -6,24 +6,62 @@ In the future, it would be nice to have this functionality built into setup.py.
Usage: Usage:
$ python scripts/build_manpage.py $ python scripts/build_manpage.py
""" """
import os
import sys
from datetime import datetime from datetime import datetime
from rtv import docs, config _filepath = os.path.dirname(os.path.relpath(__file__))
ROOT = os.path.abspath(os.path.join(_filepath, '..'))
sys.path.insert(0, ROOT)
parser = config.build_parser() import rtv
help = parser.format_help() from rtv import config
help_sections = help.split('\n\n')
data = {} def main():
data['version'] = docs.__version__ parser = config.build_parser()
data['release_date'] = datetime.utcnow().strftime('%B %d, %Y') help = parser.format_help()
data['synopsis'] = help_sections[0].replace('usage: ', '') help_sections = help.split('\n\n')
data['description'] = help_sections[1]
options = '' data = {}
arguments = help_sections[2].split('\n')[:1] print('Fetching version')
for argument in arguments: data['version'] = rtv.__version__
options += '' print('Fetching release date')
data['release_date'] = datetime.utcnow().strftime('%B %d, %Y')
print('Fetching synopsis')
synopsis = help_sections[0].replace('usage: ', '')
synopsis = ' '.join(line.strip() for line in synopsis.split('\n'))
data['synopsis'] = synopsis
print('Fetching description')
data['description'] = help_sections[1]
# Build the options section for each argument from the help section
# Example Before:
# -h, --help show this help message and exit
# Example After
# .TP
# \fB-h\fR, \fB--help\fR
# show this help message and exit
options = ''
arguments = help_sections[2].split('\n')
for argument in arguments[1:]:
argument = argument.strip()
flag, description = (col.strip() for col in argument.split(' ', 1))
flag = ', '.join(r'\fB'+f+r'\fR' for f in flag.split(', '))
options += '\n'.join(('.TP', flag, description, '\n'))
data['options'] = options
print('Fetching license')
data['license'] = rtv.__license__
print('Fetching copyright')
data['copyright'] = rtv.__copyright__
# Escape dashes is all of the sections
data = {k:v.replace('-', r'\-') for k,v in data.items()}
print('Reading from %s/templates/rtv.1' % ROOT)
with open(os.path.join(ROOT, 'templates/rtv.1')) as fp:
template = fp.read()
print('Populating template')
out = template.format(**data)
print('Writing to %s/rtv.1' % ROOT)
with open(os.path.join(ROOT, 'rtv.1'), 'w') as fp:
fp.write(out)
if __name__ == '__main__':
pass main()

View File

@@ -6,95 +6,35 @@ RTV - Reddit Terminal Viewer
.SH DESCRIPTION .SH DESCRIPTION
{description} {description}
.SH OPTIONS .SH OPTIONS
.TP {options}
\fB\-h\fR, \fB\-\-help\fR
show this help message and exit
.TP
\fB\-s\fR SUBREDDIT
subreddit name
.TP
\fB\-l\fR LINK
full link to a submission
.TP
\fB\-\-ascii\fR
enable ascii\-only mode
.TP
\fB\-\-log\fR FILE
Log HTTP requests
.PP
.SH CONTROLS .SH CONTROLS
RTV has different commands to easily navigate through subreddits and individual submissions. These can all be viewed along with a short description by pressing the \fB?\fR key at any time while running rtv. Navigate between posts by using the arrow keys or vim-style `hjkl` movement.
.PP You can view the full list of commands by pressing the \fB?\fR key inside of the program.
.SH FILES .SH FILES
.TP .TP
All config files can make use of $XDG_CONFIG_HOME which allows you to place them in other places then the given example paths. .BR $XDG_CONFIG_HOME/rtv/rtv.cfg
The configuration file can be used to customize default program settings, see
README.rst for more information.
.TP .TP
~/.config/rtv/rtv.cfg .BR $XDG_CONFIG_HOME/rtv/refresh-token
Personal configuration file. After you login to reddit, your most recent OAuth refresh token will be stored
.TP for future sessions. You can disable this behavior by setting the option
~/.config/rtv/refresh-token \fBpersistent=False\fR in your configuration file.
Session token for OAuth login, if you do not wish to have a persistent login you can set the option \fBpersistent=False\fR in the config file. But some features will not be available. .SH ENVIRONMENT
.SH CONFIG FILE EXAMPLE
.B RTV
has many options that can be set in a configuration file. Here is a simple example configuration.
.nf
[rtv]
# Log file location
log=/tmp/rtv.log
# Default subreddit
subreddit=CollegeBasketball
# Default submission link - will be opened every time the program starts
link=http://www.reddit.com/r/CollegeBasketball/comments/31irjq
# Turn on ascii-only mode and disable all unicode characters
# This may be necessary for compatibility with some terminal browsers
ascii=True
# Enable persistent storage of your authentication token
# This allows you to remain logged in when you restart the program
persistent=True
.SH ENVIROMENT VARIABLES
.B RTV
Supports enviroment variables that can help improve your experience. These options can be set in the current shell. Or placed in your configuration file for your shell of choice. Such as
.IR ~/.bashrc
or
.IR ~/.zshrc
, restarting your session will make these settings persistent for future use of
.B RTV.
.TP .TP
.BR RTV_EDITOR .BR RTV_EDITOR
Setting Specifies which text editor RTV will attempt to use when editing comments and
.IR export posts. RTV will fallback to \fI$EDITOR\fR if the editor is unspecified.
.IR RTV_EDITOR=gedit
will open gedit as your editor when composing comments and replies.
If no editor is set,
.B RTV
will fall back to the environment's default
.IR $EDITOR
, and as an extra fall back nano.
.TP .TP
.BR BROWSER .BR BROWSER
.B RTV Specifies which webbrowser RTV will attempt to use when opening links.
can open links in any browser you wish to use. Most system's will open the default such as Firefox or Chrome. But if you prefer to enjoy a terminal only experience, you can use This can be set to a terminal browser (w3m, lynx, elinks, etc.) for a true
.IR $BROWSER terminal experience. RTV will fallback to the system's default browser.
to set a browser such as w3m, lynx, and elinks. For example w3m would be
.IR export
.IR BROWSER=w3m
.PP
.SH AUTHOR .SH AUTHOR
Written by Johnathan "ShaggyTwoDope" Jenkins <twodopeshaggy@gmail.com> (2015). Man page written by Johnathan "ShaggyTwoDope" Jenkins <twodopeshaggy@gmail.com> (2015).
.SH REPORTING BUGS .SH BUGS
Report bugs to Report bugs to \fIhttps://github.com/michael-lazar/rtv/issues\fR
.I https://github.com/michael-lazar/rtv/issues .SH LICENSE
.SH COPYRIGHT {license}
Copyright \(co 2015 michael-lazar
License MIT.
.PP .PP
{copyright}