Skip to content

Commit 0496db0

Browse files
author
欧林宝
authored
0.2.0
* support Windows CLI * add cli completer rc file * bugfix: chinese code when break line in help text * bugfix: complete after the first param
1 parent 3d928d6 commit 0496db0

77 files changed

Lines changed: 14291 additions & 954 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@
3232
|发布日期|京东云CLI|京东云Python SDK|
3333
|---|---|---|
3434
|2018.06.04|0.1.0|1.1.1|
35+
|2018.06.23|0.2.0|1.1.1|
3536

3637

3738
## CLI安装方法:
38-
### Linux && Mac
39+
### Linux & Mac
3940
pip安装:
4041
`pip install jdcloud_cli`
4142

@@ -51,16 +52,50 @@ source ~/.bashrc
5152

5253

5354
### Windows
54-
开发验证中,即将发布。
55+
京东云CLI在Windows上运行依赖Git 2.9.0以上版本,建议使用最新版本。
56+
57+
下载地址为:https://git-scm.com/download/win
58+
59+
请注意:安装时模拟终端选项要选择“Use MinTTY (the default terminal of MSYS2)”。
60+
61+
pip安装:
62+
`pip install jdcloud_cli`
63+
64+
源码安装(不依赖pip):
65+
`python setup.py install`
66+
67+
安装后在git bash中执行以下脚本,打开自动完成功能:
68+
```
69+
curl https://raw.githubusercontent.com/jdcloud-api/jdcloud-cli/master/jdcloud_cli/resources/jdc.rc > ~/jdc.rc
70+
echo 'source ~/jdc.rc' >> ~/.bashrc
71+
echo 'export PYTHONIOENCODING="UTF-8"' >> ~/.bashrc
72+
source ~/.bashrc
73+
```
5574

5675
## CLI使用方法
5776
### 配置鉴权信息
58-
jdc configure -h
77+
jdc configure add --access-key your-ak --secret-key your-sk
78+
79+
说明:access-key和secret-key可以从京东云控制台申请开通。默认为华北区域。
5980

6081
### 执行产品命令
6182
jdc [options] command sub-command [--parameters values]
6283

6384
例如:
6485
jdc vm describe-instances
6586

66-
目前仅bash中支持自动完成,输入两次tab键,可提示辅助信息。
87+
目前支持Linux、Mac、Windows三种平台的Bash中的自动完成功能,输入两次tab键,可提示辅助信息。
88+
89+
创建资源时,json串的获取可以使用各产品线子命令下的 generate-skeleton 获取,如:
90+
91+
`jdc vm generate-skeleton --api create-instances`
92+
93+
更多帮助信息及OpenAPI官方文档,请见:
94+
https://www.jdcloud.com/help/faq?act=3
95+
96+
## 已知问题
97+
Windows平台中,容器交互命令为exprimental阶段。在命令前需要增加winpty前缀,如:
98+
99+
`winpty jdc nc attach --container-id c-abcdefg`
100+
101+
建议使用Linux 或 Mac平台。

cement/__init__.py

Whitespace-only changes.

cement/core/__init__.py

Whitespace-only changes.

cement/core/arg.py

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
"""
2+
Cement core argument module.
3+
4+
"""
5+
6+
from ..core import interface
7+
from ..core.handler import CementBaseHandler
8+
from ..utils.misc import minimal_logger
9+
10+
LOG = minimal_logger(__name__)
11+
12+
13+
# pylint: disable=w0613
14+
def argument_validator(klass, obj):
15+
"""Validates a handler implementation against the IArgument interface."""
16+
members = [
17+
'_setup',
18+
'parse',
19+
'add_argument',
20+
]
21+
22+
interface.validate(IArgument, obj, members)
23+
24+
25+
# pylint: disable=W0105,W0232,W0232,R0903,E0213,R0923
26+
class IArgument(interface.Interface):
27+
28+
"""
29+
This class defines the Argument Handler Interface. Classes that
30+
implement this handler must provide the methods and attributes defined
31+
below. Implementations do *not* subclass from interfaces.
32+
33+
Example:
34+
35+
.. code-block:: python
36+
37+
from cement.core import interface, arg
38+
39+
class MyArgumentHandler(arg.CementArgumentHandler):
40+
class Meta:
41+
interface = arg.IArgument
42+
label = 'my_argument_handler'
43+
44+
"""
45+
class IMeta:
46+
47+
"""Interface meta-data options."""
48+
49+
label = 'argument'
50+
"""The string identifier of the interface."""
51+
52+
validator = argument_validator
53+
"""Interface validator function."""
54+
55+
# Must be provided by the implementation
56+
Meta = interface.Attribute('Handler Meta-data')
57+
58+
def _setup(app_obj):
59+
"""
60+
The _setup function is called during application initialization and
61+
must 'setup' the handler object making it ready for the framework
62+
or the application to make further calls to it.
63+
64+
:param app_obj: The application object
65+
:returns: ``None``
66+
67+
"""
68+
69+
# pylint: disable=E0211
70+
def add_argument(*args, **kw):
71+
"""
72+
Add arguments for parsing. This should be -o/--option or positional.
73+
Note that the interface defines the following parameters so that at
74+
the very least, external extensions can guarantee that they can
75+
properly add command line arguments when necessary. The
76+
implementation itself should, and will provide and support many more
77+
options than those listed here. That said, the implementation must
78+
support the following:
79+
80+
:arg args: List of option arguments. Generally something like
81+
['-h', '--help'].
82+
:keyword dest: The destination name (var). Default: arg[0]'s string.
83+
:keyword help: The help text for --help output (for that argument).
84+
:keyword action: Must support: ['store', 'store_true', 'store_false',
85+
'store_const']
86+
:keyword choices: A list of valid values that can be passed to an
87+
option whose action is ``store``.
88+
:keyword const: The value stored if action == 'store_const'.
89+
:keyword default: The default value.
90+
:returns: ``None``
91+
92+
"""
93+
94+
def parse(arg_list):
95+
"""
96+
Parse the argument list (i.e. sys.argv). Can return any object as
97+
long as it's members contain those of the added arguments. For
98+
example, if adding a '-v/--version' option that stores to the dest of
99+
'version', then the member must be callable as 'Object().version'.
100+
101+
:param arg_list: A list of command line arguments.
102+
:returns: Callable object
103+
104+
"""
105+
106+
107+
# pylint: disable=W0105
108+
class CementArgumentHandler(CementBaseHandler):
109+
110+
"""Base class that all Argument Handlers should sub-class from."""
111+
112+
class Meta:
113+
114+
"""
115+
Handler meta-data (can be passed as keyword arguments to the parent
116+
class).
117+
"""
118+
119+
label = None
120+
"""The string identifier of the handler implementation."""
121+
122+
interface = IArgument
123+
"""The interface that this class implements."""
124+
125+
def __init__(self, *args, **kw):
126+
super(CementArgumentHandler, self).__init__(*args, **kw)

cement/core/backend.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"""Cement core backend module."""
2+
3+
VERSION = (2, 11, 1, 'alpha', 0) # pragma: nocover
4+
5+
# global hooks/handlers (DEPRECATED)
6+
__handlers__ = {} # pragma: nocover
7+
__hooks__ = {} # pragma: nocover

cement/core/cache.py

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
"""Cement core cache module."""
2+
3+
from ..core import interface, handler
4+
from ..utils.misc import minimal_logger
5+
6+
LOG = minimal_logger(__name__)
7+
8+
9+
def cache_validator(klass, obj):
10+
"""Validates a handler implementation against the ICache interface."""
11+
12+
members = [
13+
'_setup',
14+
'get',
15+
'set',
16+
'delete',
17+
'purge',
18+
]
19+
interface.validate(ICache, obj, members)
20+
21+
22+
class ICache(interface.Interface):
23+
24+
"""
25+
This class defines the Cache Handler Interface. Classes that
26+
implement this handler must provide the methods and attributes defined
27+
below.
28+
29+
Implementations do *not* subclass from interfaces.
30+
31+
Usage:
32+
33+
.. code-block:: python
34+
35+
from cement.core import cache
36+
37+
class MyCacheHandler(object):
38+
class Meta:
39+
interface = cache.ICache
40+
label = 'my_cache_handler'
41+
...
42+
43+
"""
44+
# pylint: disable=W0232, C0111, R0903
45+
class IMeta:
46+
47+
"""Interface meta-data."""
48+
49+
label = 'cache'
50+
"""The label (or type identifier) of the interface."""
51+
52+
validator = cache_validator
53+
"""Interface validator function."""
54+
55+
# Must be provided by the implementation
56+
Meta = interface.Attribute('Handler meta-data')
57+
58+
def _setup(app_obj):
59+
"""
60+
The _setup function is called during application initialization and
61+
must 'setup' the handler object making it ready for the framework
62+
or the application to make further calls to it.
63+
64+
:param app_obj: The application object.
65+
:returns: ``None``
66+
67+
"""
68+
69+
def get(key, fallback=None):
70+
"""
71+
Get the value for a key in the cache. If the key does not exist
72+
or the key/value in cache is expired, this functions must return
73+
'fallback' (which in turn must default to None).
74+
75+
:param key: The key of the value stored in cache
76+
:param fallback: Optional value that is returned if the cache is
77+
expired or the key does not exist. Default: None
78+
:returns: Unknown (whatever the value is in cache, or the `fallback`)
79+
80+
"""
81+
82+
def set(key, value, time=None):
83+
"""
84+
Set the key/value in the cache for a set amount of `time`.
85+
86+
:param key: The key of the value to store in cache.
87+
:param value: The value of that key to store in cache.
88+
:param time: A one-off expire time. If no time is given, then a
89+
default value is used (determined by the implementation).
90+
:type time: ``int`` (seconds) or ``None``
91+
:returns: ``None``
92+
93+
"""
94+
95+
def delete(key):
96+
"""
97+
Deletes a key/value from the cache.
98+
99+
:param key: The key in the cache to delete.
100+
:returns: True if the key is successfully deleted, False otherwise.
101+
:rtype: ``boolean``
102+
103+
"""
104+
105+
# pylint: disable=E0211
106+
def purge():
107+
"""
108+
Clears all data from the cache.
109+
110+
"""
111+
112+
113+
class CementCacheHandler(handler.CementBaseHandler):
114+
115+
"""
116+
Base class that all Cache Handlers should sub-class from.
117+
118+
"""
119+
class Meta:
120+
121+
"""
122+
Handler meta-data (can be passed as keyword arguments to the parent
123+
class).
124+
"""
125+
126+
label = None
127+
"""String identifier of this handler implementation."""
128+
129+
interface = ICache
130+
"""The interface that this handler class implements."""
131+
132+
def __init__(self, *args, **kw):
133+
super(CementCacheHandler, self).__init__(*args, **kw)

0 commit comments

Comments
 (0)