Compare commits
5 Commits
5de4e9496a
...
6dbdb8e43d
Author | SHA1 | Date |
---|---|---|
Nick Chambers | 6dbdb8e43d | |
Nick Chambers | 21bdb55a66 | |
Nick Chambers | 530ccba642 | |
Nick Chambers | 292d509eeb | |
Nick Chambers | 0540890cb9 |
|
@ -38,6 +38,8 @@ class Command:
|
||||||
self.needs_api_key = True
|
self.needs_api_key = True
|
||||||
self.default = "help"
|
self.default = "help"
|
||||||
|
|
||||||
|
# FIXME: add support for argument parsing
|
||||||
|
|
||||||
self.init()
|
self.init()
|
||||||
|
|
||||||
if self.needs_api_key and api_key is None:
|
if self.needs_api_key and api_key is None:
|
||||||
|
@ -48,12 +50,13 @@ class Command:
|
||||||
def exec_shortcut(self, shortcut, *args):
|
def exec_shortcut(self, shortcut, *args):
|
||||||
fn = self.find(shortcut)
|
fn = self.find(shortcut)
|
||||||
sig = inspect.signature(fn)
|
sig = inspect.signature(fn)
|
||||||
|
parity = len(sig.parameters)
|
||||||
|
|
||||||
if len(args) < len(sig.parameters):
|
if len(args) < parity:
|
||||||
name = fn.__name__[len(self.FTR_PRFX):].lower()
|
name = fn.__name__[len(self.FTR_PRFX):].lower()
|
||||||
raise NotEnoughArgs(name, len(sig.parameters) - len(args))
|
raise NotEnoughArgs(name, parity - len(args))
|
||||||
|
|
||||||
data = fn(*args)
|
data = fn(*args[:parity])
|
||||||
|
|
||||||
# FIXME: Let functions choose the output format. This will allow help
|
# FIXME: Let functions choose the output format. This will allow help
|
||||||
# functions to still return a rendering.
|
# functions to still return a rendering.
|
||||||
|
|
|
@ -1,2 +1,4 @@
|
||||||
# FIXME: build this dynamically
|
# FIXME: build this dynamically
|
||||||
__all__ = ["account", "help", "regions", "vpcs"]
|
__all__ = [
|
||||||
|
"account", "application", "backup", "billing", "help", "region", "vpc"
|
||||||
|
]
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
import vultron.cmd
|
||||||
|
|
||||||
|
class Application(vultron.cmd.Command):
|
||||||
|
def init(self):
|
||||||
|
self.needs_api_key = False
|
||||||
|
|
||||||
|
def vultron_list(self):
|
||||||
|
"""Display all available applications."""
|
||||||
|
|
||||||
|
apps = self.api.get("applications")
|
||||||
|
return apps["applications"]
|
|
@ -0,0 +1,14 @@
|
||||||
|
import vultron.cmd
|
||||||
|
|
||||||
|
class Backup(vultron.cmd.Command):
|
||||||
|
def vultron_list(self):
|
||||||
|
"""Display all stored snapshots."""
|
||||||
|
|
||||||
|
backups = self.api.get("backups")
|
||||||
|
return backups["backups"]
|
||||||
|
|
||||||
|
def vultron_get(self, backup_id):
|
||||||
|
"""Display a specific snapshot."""
|
||||||
|
|
||||||
|
backup = self.api.get("backups", backup_id)
|
||||||
|
return [backup["backup"]]
|
|
@ -1,7 +1,7 @@
|
||||||
import vultron.cmd
|
import vultron.cmd
|
||||||
import vultron.display
|
import vultron.display
|
||||||
|
|
||||||
class Regions(vultron.cmd.Command):
|
class Region(vultron.cmd.Command):
|
||||||
"""Query for information on Vultr regions."""
|
"""Query for information on Vultr regions."""
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
|
@ -13,7 +13,7 @@ class Regions(vultron.cmd.Command):
|
||||||
regions = self.api.get("regions")
|
regions = self.api.get("regions")
|
||||||
return regions["regions"]
|
return regions["regions"]
|
||||||
|
|
||||||
def vultron_plan(self, region_id):
|
def vultron_plans(self, region_id):
|
||||||
"""Display available plans for a given region."""
|
"""Display available plans for a given region."""
|
||||||
|
|
||||||
plans = self.api.get("regions", region_id, "availability")
|
plans = self.api.get("regions", region_id, "availability")
|
|
@ -1,7 +1,7 @@
|
||||||
import vultron.cmd
|
import vultron.cmd
|
||||||
import vultron.display
|
import vultron.display
|
||||||
|
|
||||||
class Vpcs(vultron.cmd.Command):
|
class Vpc(vultron.cmd.Command):
|
||||||
"""Query for information on VPCs."""
|
"""Query for information on VPCs."""
|
||||||
|
|
||||||
def vultron_list(self):
|
def vultron_list(self):
|
Loading…
Reference in New Issue