-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit allows passing country name directly to pynation. This means "pynation Somalia" works instead of "pynation info Somalia".
- Loading branch information
Showing
3 changed files
with
44 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
|
||
from click import Group, UsageError | ||
|
||
|
||
class DefaultCommand(Group): | ||
|
||
def command(self, *args, **kwargs): | ||
default_command = kwargs.pop("default_command", False) | ||
if default_command and not args: | ||
kwargs["name"] = kwargs.get("name", "info") | ||
|
||
decorator = super(DefaultCommand, self).command(*args, **kwargs) | ||
if default_command: | ||
def new_decorator(f): | ||
cmd = decorator(f) | ||
self.default_command = cmd.name | ||
cmd.hidden = True # Hide "->" from the command line | ||
return cmd | ||
return new_decorator | ||
|
||
return decorator | ||
|
||
def resolve_command(self, ctx, args): | ||
try: | ||
return super(DefaultCommand, self).resolve_command(ctx, args) | ||
except UsageError: | ||
# Since "country_name" is not a command name, we want to pass "->" | ||
args.insert(0, self.default_command) | ||
return super(DefaultCommand, self).resolve_command(ctx, args) | ||
|
||
|
||
def return_country(data_source, column): | ||
_country = data_source.get(column.title(), None) | ||
if _country is not None: | ||
return _country |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters