-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add --version #182
base: devel
Are you sure you want to change the base?
Add --version #182
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ | |
{self} [--path=<path>] [-v...] <target> (gist|snippet) delete <gist> [-f] | ||
{self} [--path=<path>] [-v...] <target> config [--config=<gitconfig>] | ||
{self} [-v...] config [--config=<gitconfig>] | ||
{self} --version | ||
{self} --help | ||
|
||
Tool for managing remote repository services. | ||
|
@@ -52,6 +53,7 @@ | |
<namespace>/<repo> Repository to work with | ||
-p,--path=<path> Path to work on [default: .] | ||
-v,--verbose Makes it more chatty (repeat twice to see git commands) | ||
--version Show the version | ||
-h,--help Shows this message | ||
|
||
Options for list: | ||
|
@@ -142,7 +144,7 @@ | |
from .tools import print_tty, print_iter, loop_input, confirm | ||
from .kwargparse import KeywordArgumentParser, store_parameter, register_action | ||
|
||
from git import Repo, Git | ||
from git import Repo, Git, __version__ as GitPythonVersion | ||
from git.exc import InvalidGitRepositoryError, NoSuchPathError, BadName | ||
|
||
class GitRepoRunner(KeywordArgumentParser): | ||
|
@@ -586,9 +588,39 @@ def main(args): | |
return 2 | ||
|
||
|
||
class Version: | ||
def __str__(self): | ||
import importlib | ||
s = ['Version: {}'.format(__version__), | ||
' GitPython: {}'.format(GitPythonVersion), | ||
' Services:' | ||
] | ||
services = RepositoryService.service_map.values() | ||
|
||
for service in sorted(services, key=lambda s: s.name): | ||
version = 'unknown' | ||
try: | ||
mod = importlib.import_module(service.__module__) | ||
package = mod.SERVICE_PACKAGE | ||
client = package.__name__ | ||
except: | ||
client = 'unknown' | ||
else: | ||
try: | ||
version = package.__version__ | ||
except AttributeError: | ||
pass | ||
|
||
s.append(' {}:'.format(service.name)) | ||
s.append(' {}: {}'.format(client, version)) | ||
|
||
return '\n'.join(s) | ||
|
||
|
||
def cli(): # pragma: no cover | ||
try: | ||
sys.exit(main(docopt(__doc__.format(self=sys.argv[0].split(os.path.sep)[-1], version=__version__)))) | ||
sys.exit(main(docopt(__doc__.format(self=sys.argv[0].split(os.path.sep)[-1], version=__version__), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the |
||
version=Version()))) | ||
finally: | ||
# Whatever happens, make sure that the cursor reappears with some ANSI voodoo | ||
if sys.stdout.isatty(): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
from ...exceptions import ResourceError, ResourceExistsError, ResourceNotFoundError | ||
from ...tools import columnize | ||
|
||
import pybitbucket | ||
from pybitbucket.bitbucket import Client, Bitbucket | ||
from pybitbucket.auth import BasicAuthenticator | ||
from pybitbucket.pullrequest import PullRequest, PullRequestPayload | ||
|
@@ -26,6 +27,9 @@ | |
import os, json, platform | ||
|
||
|
||
SERVICE_PACKAGE = pybitbucket | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't really like that pattern, it feels a bit redundant with the register target decorator. What I'd rather do is either make a new decorator that manages version, or add an argument to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the other better side of that is that you don't need the full loading of the module into the main system, and if a module has a version string that's not standard (i.e. not using |
||
|
||
|
||
@register_target('bb', 'bitbucket') | ||
class BitbucketService(RepositoryService): | ||
fqdn = 'bitbucket.org' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be moved to either: