Skip to content

Commit faac3de

Browse files
Merge pull request #311 from ricardoquesada/list_platforms
List platforms
2 parents e4138fa + b027b12 commit faac3de

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

bin/cocos

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#!/bin/sh
1+
#!/bin/bash -l
22

33
COCOS_CONSOLE_BIN_DIRECTORY=$(dirname "$0")
44
COCOS_CONSOLE_BIN_DIRECTORY=$(cd "$COCOS_CONSOLE_BIN_DIRECTORY" && pwd -P)
55

6-
exec python "$COCOS_CONSOLE_BIN_DIRECTORY/cocos.py" "$@"
6+
python "$COCOS_CONSOLE_BIN_DIRECTORY/cocos.py" "$@"
77

bin/cocos.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@
2424
import string
2525
import locale
2626
import gettext
27+
import json
28+
2729

2830
# FIXME: MultiLanguage should be deprecated in favor of gettext
2931
from MultiLanguage import MultiLanguage
3032

31-
COCOS2D_CONSOLE_VERSION = '2.0'
33+
COCOS2D_CONSOLE_VERSION = '2.1'
3234

3335

3436
class Cocos2dIniParser:
@@ -257,8 +259,6 @@ class DataStatistic(object):
257259
# change the last time statistics status in local config file.
258260
@classmethod
259261
def change_last_state(cls, cfg_file, enabled):
260-
import json
261-
262262
# get current local config info
263263
if not os.path.isfile(cfg_file):
264264
cur_info = {}
@@ -281,8 +281,6 @@ def change_last_state(cls, cfg_file, enabled):
281281
# get the last time statistics status in local config file.
282282
@classmethod
283283
def get_last_state(cls, cfg_file):
284-
import json
285-
286284
# get the config
287285
if not os.path.isfile(cfg_file):
288286
cur_info = None
@@ -532,6 +530,8 @@ def _check_custom_options(self, args):
532530
def parse_args(self, argv):
533531
from argparse import ArgumentParser
534532

533+
# FIXME:
534+
# CCPlugin should not parse any argument. Plugins are responsoble for doing it
535535
parser = ArgumentParser(prog="cocos %s" % self.__class__.plugin_name(),
536536
description=self.__class__.brief_description())
537537
parser.add_argument("-s", "--src",
@@ -545,6 +545,10 @@ def parse_args(self, argv):
545545
parser.add_argument("-p", "--platform",
546546
dest="platform",
547547
help=MultiLanguage.get_string('COCOS_HELP_ARG_PLATFORM'))
548+
parser.add_argument("--list-platforms",
549+
action="store_true",
550+
dest="listplatforms",
551+
help=_("List available platforms"))
548552
parser.add_argument("--proj-dir",
549553
dest="proj_dir",
550554
help=MultiLanguage.get_string('COCOS_HELP_ARG_PROJ_DIR'))
@@ -569,6 +573,12 @@ def parse_args(self, argv):
569573
raise CCPluginError(MultiLanguage.get_string('COCOS_ERROR_UNKNOWN_PLATFORM_FMT', args.platform),
570574
CCPluginError.ERROR_WRONG_ARGS)
571575

576+
if args.listplatforms and self._project is not None:
577+
platforms = cocos_project.Platforms(self._project, args.platform, args.proj_dir)
578+
p = platforms.get_available_platforms().keys()
579+
print('{"platforms":' + json.dumps(p) + '}')
580+
sys.exit(0)
581+
572582
self.init(args)
573583
self._check_custom_options(args)
574584

0 commit comments

Comments
 (0)