Fix bug in args & less-aggressive update
Without args.prog, AliasCommand fail. Alias is better documented in the readme and initial config files. Update will now only trigger with version bumps. And the plugins section is not updated. Removes the --upgrade flag.
This commit is contained in:
parent
ba48941d93
commit
7186576aef
@ -71,6 +71,14 @@ pages = string(default='')
|
|||||||
# comma-separated list of the plugins to load
|
# comma-separated list of the plugins to load
|
||||||
active = list(default=list())
|
active = list(default=list())
|
||||||
|
|
||||||
|
[[alias]]
|
||||||
|
# new subcommands can be defined, e.g.:
|
||||||
|
# print = open --with lp
|
||||||
|
# evince = open --with evince
|
||||||
|
|
||||||
|
# shell commands can also be defined, by prefixing them with a bang `!`, e.g:
|
||||||
|
# count = !pubs list -k | wc -l
|
||||||
|
|
||||||
[internal]
|
[internal]
|
||||||
# The version of this configuration file. Do not edit.
|
# The version of this configuration file. Do not edit.
|
||||||
version = string(min=5, default='{}')
|
version = string(min=5, default='{}')
|
||||||
|
@ -33,15 +33,15 @@ CORE_CMDS = collections.OrderedDict([
|
|||||||
|
|
||||||
def execute(raw_args=sys.argv):
|
def execute(raw_args=sys.argv):
|
||||||
|
|
||||||
conf_parser = argparse.ArgumentParser(add_help=False)
|
conf_parser = argparse.ArgumentParser(prog="pubs", add_help=False)
|
||||||
conf_parser.add_argument("-c", "--config", help="path to config file",
|
conf_parser.add_argument("-c", "--config", help="path to config file",
|
||||||
type=str, metavar="FILE")
|
type=str, metavar="FILE")
|
||||||
conf_parser.add_argument("-u", "--update", help="update config if needed",
|
#conf_parser.add_argument("-u", "--update", help="update config if needed",
|
||||||
default=False, action='store_true')
|
# default=False, action='store_true')
|
||||||
args, remaining_args = conf_parser.parse_known_args(raw_args[1:])
|
top_args, remaining_args = conf_parser.parse_known_args(raw_args[1:])
|
||||||
|
|
||||||
if args.config:
|
if top_args.config:
|
||||||
conf_path = args.config
|
conf_path = top_args.config
|
||||||
else:
|
else:
|
||||||
conf_path = config.get_confpath(verify=False) # will be checked on load
|
conf_path = config.get_confpath(verify=False) # will be checked on load
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ def execute(raw_args=sys.argv):
|
|||||||
if len(remaining_args) > 0 and remaining_args[0] != 'init':
|
if len(remaining_args) > 0 and remaining_args[0] != 'init':
|
||||||
try:
|
try:
|
||||||
conf = config.load_conf(path=conf_path, check=False)
|
conf = config.load_conf(path=conf_path, check=False)
|
||||||
if args.update and update.update_check(conf, path=conf.filename):
|
if update.update_check(conf, path=conf.filename):
|
||||||
# an update happened, reload conf.
|
# an update happened, reload conf.
|
||||||
conf = config.load_conf(path=conf_path, check=False)
|
conf = config.load_conf(path=conf_path, check=False)
|
||||||
config.check_conf(conf)
|
config.check_conf(conf)
|
||||||
@ -81,4 +81,5 @@ def execute(raw_args=sys.argv):
|
|||||||
|
|
||||||
# Parse and run appropriate command
|
# Parse and run appropriate command
|
||||||
args = parser.parse_args(remaining_args)
|
args = parser.parse_args(remaining_args)
|
||||||
|
args.prog = "pubs" # FIXME?
|
||||||
args.func(conf, args)
|
args.func(conf, args)
|
||||||
|
@ -69,7 +69,7 @@ def update(conf, code_version, repo_version, path=None):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
# continuous update while configuration is stabilizing
|
# continuous update while configuration is stabilizing
|
||||||
if repo_version == code_version == ['0', '6', '0']:
|
if repo_version == ['0', '6', '0'] and repo_version < code_version:
|
||||||
default_conf = config.load_default_conf()
|
default_conf = config.load_default_conf()
|
||||||
for section_name, section in conf.items():
|
for section_name, section in conf.items():
|
||||||
for key, value in section.items():
|
for key, value in section.items():
|
||||||
@ -78,6 +78,10 @@ def update(conf, code_version, repo_version, path=None):
|
|||||||
default_conf[section_name][key] = value
|
default_conf[section_name][key] = value
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
# we don't update plugins
|
||||||
|
for section_name, section in conf['plugins'].items():
|
||||||
|
default_conf[section_name]['plugins'][section_name] = section
|
||||||
|
|
||||||
|
|
||||||
# comparing potential changes
|
# comparing potential changes
|
||||||
with open(path, 'r') as f:
|
with open(path, 'r') as f:
|
||||||
@ -85,7 +89,6 @@ def update(conf, code_version, repo_version, path=None):
|
|||||||
new_conf_text = io.BytesIO()
|
new_conf_text = io.BytesIO()
|
||||||
default_conf.write(outfile=new_conf_text)
|
default_conf.write(outfile=new_conf_text)
|
||||||
|
|
||||||
|
|
||||||
if new_conf_text.getvalue() != old_conf_text:
|
if new_conf_text.getvalue() != old_conf_text:
|
||||||
|
|
||||||
backup_path = path + '.old'
|
backup_path = path + '.old'
|
||||||
|
14
readme.md
14
readme.md
@ -52,16 +52,16 @@ This ensure that your reference file is always up-to-date; you can cite a paper
|
|||||||
|
|
||||||
and then add `\cite{Loeb_2012}` in your manuscript. After running the bash script, the citation will correctly appear in your compiled pdf.
|
and then add `\cite{Loeb_2012}` in your manuscript. After running the bash script, the citation will correctly appear in your compiled pdf.
|
||||||
|
|
||||||
Customization
|
## Customization
|
||||||
-------------
|
|
||||||
Pubs is designed to interact well with your command line tool chain. You can add custom commands to pubs by defining aliases in your config file. Here are a few examples.
|
|
||||||
|
|
||||||
[alias]
|
Pubs is designed to interact well with your command line tool chain. You can add custom commands to pubs by defining aliases in your config file.
|
||||||
print = open -w lp
|
|
||||||
|
[[alias]]
|
||||||
|
evince = open --with evince
|
||||||
count = !pubs list -k | wc -l
|
count = !pubs list -k | wc -l
|
||||||
|
|
||||||
For more advanced functionalities, pubs also support plugins. Actually *alias* is itself a plugin!
|
The first command defines a new subcommand: `pubs open -w lp` will be executed when `pubs print` is typed.
|
||||||
|
The second starts with a bang: `!`, and is treated as a shell command.
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user