gibson-cli 0.5.2__py3-none-any.whl → 0.5.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. gibson/api/BaseApi.py +9 -1
  2. gibson/api/Cli.py +5 -12
  3. gibson/api/ProjectApi.py +13 -0
  4. gibson/command/Build.py +3 -3
  5. gibson/command/Conf.py +4 -4
  6. gibson/command/Count.py +3 -3
  7. gibson/command/Dev.py +3 -3
  8. gibson/command/Forget.py +3 -3
  9. gibson/command/Import.py +5 -5
  10. gibson/command/Merge.py +1 -1
  11. gibson/command/Model.py +3 -3
  12. gibson/command/Modify.py +3 -3
  13. gibson/command/OpenApi.py +3 -3
  14. gibson/command/Question.py +6 -6
  15. gibson/command/Remove.py +3 -3
  16. gibson/command/Schema.py +3 -3
  17. gibson/command/Show.py +10 -7
  18. gibson/command/Test.py +3 -3
  19. gibson/command/Tree.py +1 -1
  20. gibson/command/Version.py +5 -8
  21. gibson/command/auth/Auth.py +3 -3
  22. gibson/command/code/Code.py +26 -0
  23. gibson/command/{Code.py → code/Entity.py} +2 -20
  24. gibson/command/{List.py → list/Entities.py} +2 -15
  25. gibson/command/list/List.py +27 -0
  26. gibson/command/list/Projects.py +25 -0
  27. gibson/command/new/Module.py +8 -6
  28. gibson/command/new/New.py +4 -4
  29. gibson/command/{Rename.py → rename/Entity.py} +9 -21
  30. gibson/command/rename/Rename.py +21 -0
  31. gibson/command/rewrite/Rewrite.py +4 -4
  32. gibson/core/CommandRouter.py +3 -8
  33. gibson/core/Configuration.py +22 -15
  34. gibson/core/Conversation.py +9 -2
  35. {gibson_cli-0.5.2.dist-info → gibson_cli-0.5.4.dist-info}/METADATA +1 -1
  36. {gibson_cli-0.5.2.dist-info → gibson_cli-0.5.4.dist-info}/RECORD +39 -34
  37. {gibson_cli-0.5.2.dist-info → gibson_cli-0.5.4.dist-info}/WHEEL +1 -1
  38. {gibson_cli-0.5.2.dist-info → gibson_cli-0.5.4.dist-info}/entry_points.txt +0 -0
  39. {gibson_cli-0.5.2.dist-info → gibson_cli-0.5.4.dist-info}/top_level.txt +0 -0
gibson/api/BaseApi.py CHANGED
@@ -25,7 +25,15 @@ class BaseApi:
25
25
  return r.json()
26
26
 
27
27
  def headers(self):
28
- raise NotImplementedError
28
+ headers = {
29
+ "X-Gibson-Client-ID": self.configuration.client_id(),
30
+ }
31
+
32
+ token = self.configuration.get_access_token()
33
+ if token is not None:
34
+ headers["Authorization"] = f"Bearer {token}"
35
+
36
+ return headers
29
37
 
30
38
  def post(self, endpoint, json: dict):
31
39
  r = requests.post(self.url(endpoint), headers=self.headers(), json=json)
gibson/api/Cli.py CHANGED
@@ -1,16 +1,16 @@
1
+ from gibson.api.BaseApi import BaseApi
1
2
  from gibson.core.Configuration import Configuration
2
3
  from gibson.core.Memory import Memory
3
4
  from gibson.lang.Python import Python
4
5
 
5
- from .BaseApi import BaseApi
6
-
7
6
 
8
7
  class Cli(BaseApi):
9
8
  PREFIX = "cli"
10
9
 
11
10
  def __init__(self, configuration: Configuration):
12
11
  self.configuration = configuration
13
- self.configuration.ensure_project()
12
+ self.configuration.require_login()
13
+ self.configuration.require_project()
14
14
 
15
15
  def code_api(self):
16
16
  return self.post(
@@ -64,15 +64,8 @@ class Cli(BaseApi):
64
64
  ).json()
65
65
 
66
66
  def headers(self):
67
- headers = {
68
- "X-Gibson-Client-ID": self.configuration.client_id(),
69
- "X-Gibson-API-Key": self.configuration.project.api.key,
70
- }
71
-
72
- token = self.configuration.get_access_token()
73
- if token is not None:
74
- headers["Authorization"] = f"Bearer {token}"
75
-
67
+ headers = super().headers()
68
+ headers["X-Gibson-API-Key"] = self.configuration.project.api.key
76
69
  return headers
77
70
 
78
71
  def import_(self):
@@ -0,0 +1,13 @@
1
+ from gibson.api.BaseApi import BaseApi
2
+ from gibson.core.Configuration import Configuration
3
+
4
+
5
+ class ProjectApi(BaseApi):
6
+ PREFIX = "project"
7
+
8
+ def __init__(self, configuration: Configuration):
9
+ self.configuration = configuration
10
+ self.configuration.require_login()
11
+
12
+ def all_projects(self):
13
+ return self.get("all")["projects"]
gibson/command/Build.py CHANGED
@@ -3,8 +3,8 @@ import sys
3
3
  from sqlalchemy import create_engine
4
4
  from sqlalchemy.orm import sessionmaker
5
5
 
6
+ import gibson.core.Colors as Colors
6
7
  from gibson.command.BaseCommand import BaseCommand
7
- from gibson.core.Colors import argument, command, hint, subcommand
8
8
  from gibson.db.TableExceptions import TableExceptions
9
9
 
10
10
 
@@ -49,7 +49,7 @@ class Build(BaseCommand):
49
49
  if len(sys.argv) != 3 or sys.argv[2] != "datastore":
50
50
  self.usage()
51
51
 
52
- self.configuration.ensure_project()
52
+ self.configuration.require_project()
53
53
 
54
54
  if self.memory.entities is None or len(self.memory.entities) == 0:
55
55
  self.no_entities()
@@ -72,7 +72,7 @@ class Build(BaseCommand):
72
72
  else ""
73
73
  )
74
74
  self.conversation.type(
75
- f"usage: {command(self.configuration.command)} {subcommand('build')} {argument('datastore')} {hint('build the datastore')} {datastore_uri}\n"
75
+ f"usage: {Colors.command(self.configuration.command)} {Colors.subcommand('build')} {Colors.argument('datastore')} {Colors.hint('build the datastore')} {datastore_uri}\n"
76
76
  )
77
77
  self.conversation.newline()
78
78
  exit(1)
gibson/command/Conf.py CHANGED
@@ -1,7 +1,7 @@
1
1
  import sys
2
2
 
3
+ import gibson.core.Colors as Colors
3
4
  from gibson.command.BaseCommand import BaseCommand
4
- from gibson.core.Colors import argument, command, hint, input, subcommand
5
5
 
6
6
 
7
7
  class Conf(BaseCommand):
@@ -39,7 +39,7 @@ class Conf(BaseCommand):
39
39
  except KeyError:
40
40
  self.usage()
41
41
 
42
- self.configuration.ensure_project()
42
+ self.configuration.require_project()
43
43
  self.configuration.display_project()
44
44
  self.conversation.type(f"{key}\n")
45
45
  self.conversation.type(f" [old value] {old_value}\n")
@@ -61,12 +61,12 @@ class Conf(BaseCommand):
61
61
  def usage(self):
62
62
  self.configuration.display_project()
63
63
  self.conversation.type(
64
- f"usage: {command(self.configuration.command)} {subcommand('conf')} {argument('[key]')} {input('[value]')} {hint('set a configuration value')}\n"
64
+ f"usage: {Colors.command(self.configuration.command)} {Colors.subcommand('conf')} {Colors.argument('[key]')} {Colors.input('[value]')} {Colors.hint('set a configuration value')}\n"
65
65
  )
66
66
  self.conversation.newline()
67
67
 
68
68
  if self.configuration.project:
69
- self.conversation.type(f" where {argument('[key]')} is one of:\n")
69
+ self.conversation.type(f" where {Colors.argument('[key]')} is one of:\n")
70
70
  self.conversation.set_delay(0.004)
71
71
 
72
72
  for key in self.get_configuration_keys():
gibson/command/Count.py CHANGED
@@ -1,7 +1,7 @@
1
1
  import sys
2
2
 
3
+ import gibson.core.Colors as Colors
3
4
  from gibson.command.BaseCommand import BaseCommand
4
- from gibson.core.Colors import arguments, command, hint, subcommand
5
5
 
6
6
 
7
7
  class Count(BaseCommand):
@@ -9,7 +9,7 @@ class Count(BaseCommand):
9
9
  if len(sys.argv) != 3 or sys.argv[2] not in ["last", "stored"]:
10
10
  self.usage()
11
11
 
12
- self.configuration.ensure_project()
12
+ self.configuration.require_project()
13
13
 
14
14
  if sys.argv[2] == "last":
15
15
  count = 0
@@ -31,7 +31,7 @@ class Count(BaseCommand):
31
31
  def usage(self):
32
32
  self.configuration.display_project()
33
33
  self.conversation.type(
34
- f"usage: {command(self.configuration.command)} {subcommand('count')} {arguments(['last', 'stored'])} {hint('display the number of entities')}\n"
34
+ f"usage: {Colors.command(self.configuration.command)} {Colors.subcommand('count')} {Colors.arguments(['last', 'stored'])} {Colors.hint('display the number of entities')}\n"
35
35
  )
36
36
  self.conversation.newline()
37
37
  exit(1)
gibson/command/Dev.py CHANGED
@@ -1,8 +1,8 @@
1
1
  import os
2
2
  import sys
3
3
 
4
+ import gibson.core.Colors as Colors
4
5
  from gibson.command.BaseCommand import BaseCommand
5
- from gibson.core.Colors import arguments, command, hint, subcommand
6
6
  from gibson.lang.Python import Python
7
7
 
8
8
 
@@ -30,7 +30,7 @@ class Dev(BaseCommand):
30
30
  if len(sys.argv) != 3 or sys.argv[2] not in ["off", "on"]:
31
31
  self.usage()
32
32
 
33
- self.configuration.ensure_project()
33
+ self.configuration.require_project()
34
34
 
35
35
  if sys.argv[2] == "off":
36
36
  if self.configuration.project.dev.active is True:
@@ -119,7 +119,7 @@ class Dev(BaseCommand):
119
119
  def usage(self):
120
120
  self.configuration.display_project()
121
121
  self.conversation.type(
122
- f"usage: {command(self.configuration.command)} {subcommand('dev')} {arguments(['off', 'on'])} {hint('turn dev mode on or off')}\n"
122
+ f"usage: {Colors.command(self.configuration.command)} {Colors.subcommand('dev')} {Colors.arguments(['off', 'on'])} {Colors.hint('turn dev mode on or off')}\n"
123
123
  )
124
124
  self.conversation.newline()
125
125
  exit(1)
gibson/command/Forget.py CHANGED
@@ -1,7 +1,7 @@
1
1
  import sys
2
2
 
3
+ import gibson.core.Colors as Colors
3
4
  from gibson.command.BaseCommand import BaseCommand
4
- from gibson.core.Colors import arguments, command, hint, subcommand
5
5
 
6
6
 
7
7
  class Forget(BaseCommand):
@@ -9,7 +9,7 @@ class Forget(BaseCommand):
9
9
  if len(sys.argv) != 3 or sys.argv[2] not in ["all", "last", "stored"]:
10
10
  self.usage()
11
11
 
12
- self.configuration.ensure_project()
12
+ self.configuration.require_project()
13
13
  self.configuration.display_project()
14
14
 
15
15
  if sys.argv[2] in ["all", "last"]:
@@ -27,7 +27,7 @@ class Forget(BaseCommand):
27
27
  def usage(self):
28
28
  self.configuration.display_project()
29
29
  self.conversation.type(
30
- f"usage: {command(self.configuration.command)} {subcommand('forget')} {arguments(['all', 'last', 'stored'])} {hint('delete entities from memory')}\n"
30
+ f"usage: {Colors.command(self.configuration.command)} {Colors.subcommand('forget')} {Colors.arguments(['all', 'last', 'stored'])} {Colors.hint('delete entities from memory')}\n"
31
31
  )
32
32
  self.conversation.newline()
33
33
  exit(1)
gibson/command/Import.py CHANGED
@@ -3,10 +3,10 @@ import sys
3
3
  from sqlalchemy import create_engine
4
4
  from sqlalchemy.orm import sessionmaker
5
5
 
6
+ import gibson.core.Colors as Colors
6
7
  from gibson.api.Cli import Cli
7
8
  from gibson.command.BaseCommand import BaseCommand
8
9
  from gibson.command.rewrite.Rewrite import Rewrite
9
- from gibson.core.Colors import argument, arguments, command, hint, option, subcommand
10
10
  from gibson.db.TableExceptions import TableExceptions
11
11
 
12
12
 
@@ -15,7 +15,7 @@ class Import(BaseCommand):
15
15
  if len(sys.argv) != 3 and len(sys.argv) != 5:
16
16
  self.usage()
17
17
 
18
- self.configuration.ensure_project()
18
+ self.configuration.require_project()
19
19
  write_code = False
20
20
  if len(sys.argv) == 5:
21
21
  if sys.argv[3] != ".." or sys.argv[4] != "dev":
@@ -106,13 +106,13 @@ class Import(BaseCommand):
106
106
  else ""
107
107
  )
108
108
  self.conversation.type(
109
- f"usage: {command(self.configuration.command)} {subcommand('import')} {argument('api')} {hint('import all entities from your project created on GibsonAI.com')}\n"
109
+ f"usage: {Colors.command(self.configuration.command)} {Colors.subcommand('import')} {Colors.argument('api')} {Colors.hint('import all entities from your project created on GibsonAI.com')}\n"
110
110
  )
111
111
  self.conversation.type(
112
- f" or: {command(self.configuration.command)} {subcommand('import')} {argument('datastore')} {hint('import all entities from your local datastore')} {datastore_uri}\n"
112
+ f" or: {Colors.command(self.configuration.command)} {Colors.subcommand('import')} {Colors.argument('datastore')} {Colors.hint('import all entities from your local datastore')} {datastore_uri}\n"
113
113
  )
114
114
  self.conversation.type(
115
- f" or: {command(self.configuration.command)} {subcommand('import')} {arguments(['api', 'datastore'])} {option('.. dev')} {hint('have dev mode write all the code')}\n"
115
+ f" or: {Colors.command(self.configuration.command)} {Colors.subcommand('import')} {Colors.arguments(['api', 'datastore'])} {Colors.option('.. dev')} {Colors.hint('have dev mode write all the code')}\n"
116
116
  )
117
117
  self.conversation.newline()
118
118
  exit(1)
gibson/command/Merge.py CHANGED
@@ -3,7 +3,7 @@ from gibson.command.BaseCommand import BaseCommand
3
3
 
4
4
  class Merge(BaseCommand):
5
5
  def execute(self):
6
- self.configuration.ensure_project()
6
+ self.configuration.require_project()
7
7
  self.configuration.display_project()
8
8
 
9
9
  if self.memory.last is None or "entities" not in self.memory.last:
gibson/command/Model.py CHANGED
@@ -1,8 +1,8 @@
1
1
  import sys
2
2
 
3
+ import gibson.core.Colors as Colors
3
4
  from gibson.api.Cli import Cli
4
5
  from gibson.command.BaseCommand import BaseCommand
5
- from gibson.core.Colors import command, hint, input, subcommand
6
6
  from gibson.core.TimeKeeper import TimeKeeper
7
7
  from gibson.dev.Dev import Dev
8
8
 
@@ -12,7 +12,7 @@ class Model(BaseCommand):
12
12
  if len(sys.argv) != 3:
13
13
  self.usage()
14
14
 
15
- self.configuration.ensure_project()
15
+ self.configuration.require_project()
16
16
  entity = self.memory.recall_stored_entity(sys.argv[2])
17
17
  if entity is None:
18
18
  self.conversation.not_sure_no_entity(
@@ -35,7 +35,7 @@ class Model(BaseCommand):
35
35
  def usage(self):
36
36
  self.configuration.display_project()
37
37
  self.conversation.type(
38
- f"usage: {command(self.configuration.command)} {subcommand('model')} {input('[entity name]')} {hint('generate the model for an entity')}\n"
38
+ f"usage: {Colors.command(self.configuration.command)} {Colors.subcommand('model')} {Colors.input('[entity name]')} {Colors.hint('generate the model for an entity')}\n"
39
39
  )
40
40
  self.conversation.newline()
41
41
  exit(1)
gibson/command/Modify.py CHANGED
@@ -1,8 +1,8 @@
1
1
  import sys
2
2
 
3
+ import gibson.core.Colors as Colors
3
4
  from gibson.api.Cli import Cli
4
5
  from gibson.command.BaseCommand import BaseCommand
5
- from gibson.core.Colors import argument, command, hint, input, subcommand
6
6
 
7
7
 
8
8
  class Modify(BaseCommand):
@@ -10,7 +10,7 @@ class Modify(BaseCommand):
10
10
  if len(sys.argv) < 4:
11
11
  self.usage()
12
12
 
13
- self.configuration.ensure_project()
13
+ self.configuration.require_project()
14
14
  entity = self.memory.recall_entity(sys.argv[2])
15
15
  if entity is None:
16
16
  self.conversation.not_sure_no_entity(
@@ -34,7 +34,7 @@ class Modify(BaseCommand):
34
34
  def usage(self):
35
35
  self.configuration.display_project()
36
36
  self.conversation.type(
37
- f"usage: {command(self.configuration.command)} {subcommand('modify')} {argument('[entity name]')} {input('[instructions]')} {hint('modify an entity with natural language instructions')}\n"
37
+ f"usage: {Colors.command(self.configuration.command)} {Colors.subcommand('modify')} {Colors.argument('[entity name]')} {Colors.input('[instructions]')} {Colors.hint('modify an entity with natural language instructions')}\n"
38
38
  )
39
39
  self.conversation.newline()
40
40
  exit(1)
gibson/command/OpenApi.py CHANGED
@@ -2,9 +2,9 @@ import json
2
2
  import re
3
3
  import sys
4
4
 
5
+ import gibson.core.Colors as Colors
5
6
  from gibson.api.Cli import Cli
6
7
  from gibson.command.BaseCommand import BaseCommand
7
- from gibson.core.Colors import command, hint, input, subcommand
8
8
 
9
9
 
10
10
  class OpenApi(BaseCommand):
@@ -31,7 +31,7 @@ class OpenApi(BaseCommand):
31
31
  if "paths" not in contents:
32
32
  self.unrecognized_format()
33
33
 
34
- self.configuration.ensure_project()
34
+ self.configuration.require_project()
35
35
  self.configuration.display_project()
36
36
 
37
37
  if contents.get("info", None) is not None:
@@ -135,7 +135,7 @@ class OpenApi(BaseCommand):
135
135
  def usage(self):
136
136
  self.configuration.display_project()
137
137
  self.conversation.type(
138
- f"usage: {command(self.configuration.command)} {subcommand('openapi')} {input('[file path]')} {hint('import entities from an OpenAPI spec file')}\n"
138
+ f"usage: {Colors.command(self.configuration.command)} {Colors.subcommand('openapi')} {Colors.input('[file path]')} {Colors.hint('import entities from an OpenAPI spec file')}\n"
139
139
  )
140
140
  self.conversation.newline()
141
141
  exit(1)
@@ -1,9 +1,9 @@
1
1
  import os
2
2
  import sys
3
3
 
4
+ import gibson.core.Colors as Colors
4
5
  from gibson.api.Cli import Cli
5
6
  from gibson.command.BaseCommand import BaseCommand
6
- from gibson.core.Colors import argument, command, hint, input, subcommand
7
7
 
8
8
 
9
9
  class Question(BaseCommand):
@@ -15,7 +15,7 @@ class Question(BaseCommand):
15
15
  if len(sys.argv) < 3:
16
16
  self.usage()
17
17
 
18
- self.configuration.ensure_project()
18
+ self.configuration.require_project()
19
19
  instructions = ""
20
20
  has_file = False
21
21
  has_python = False
@@ -96,16 +96,16 @@ class Question(BaseCommand):
96
96
  def usage(self):
97
97
  self.configuration.display_project()
98
98
  self.conversation.type(
99
- f"usage: {command(self.configuration.command)} {subcommand('q')} {input('[instructions]')} {hint('ask a question or tell Gibson to do something using natural language')}\n"
99
+ f"usage: {Colors.command(self.configuration.command)} {Colors.subcommand('q')} {Colors.input('[instructions]')} {Colors.hint('ask a question or tell Gibson to do something using natural language')}\n"
100
100
  )
101
101
  self.conversation.type(
102
- f" use {argument(self.TOKEN_FILE+'[path]')} to import a file from the filesystem\n"
102
+ f" use {Colors.argument(self.TOKEN_FILE+'[path]')} to import a file from the filesystem\n"
103
103
  )
104
104
  self.conversation.type(
105
- f" use {argument(self.TOKEN_PYTHON+'[import]')} to import a file from PYTHONPATH\n"
105
+ f" use {Colors.argument(self.TOKEN_PYTHON+'[import]')} to import a file from PYTHONPATH\n"
106
106
  )
107
107
  self.conversation.type(
108
- f" use {argument(self.TOKEN_SQL+'[entity name]')} to import SQL\n"
108
+ f" use {Colors.argument(self.TOKEN_SQL+'[entity name]')} to import SQL\n"
109
109
  )
110
110
 
111
111
  self.conversation.newline()
gibson/command/Remove.py CHANGED
@@ -1,9 +1,9 @@
1
1
  import sys
2
2
 
3
+ import gibson.core.Colors as Colors
3
4
  from gibson.api.Cli import Cli
4
5
  from gibson.command.BaseCommand import BaseCommand
5
6
  from gibson.command.rewrite.Rewrite import Rewrite
6
- from gibson.core.Colors import command, hint, input, subcommand
7
7
 
8
8
 
9
9
  class Remove(BaseCommand):
@@ -11,7 +11,7 @@ class Remove(BaseCommand):
11
11
  if len(sys.argv) != 3:
12
12
  self.usage()
13
13
 
14
- self.configuration.ensure_project()
14
+ self.configuration.require_project()
15
15
  self.configuration.display_project()
16
16
 
17
17
  found = False
@@ -74,7 +74,7 @@ class Remove(BaseCommand):
74
74
  def usage(self):
75
75
  self.configuration.display_project()
76
76
  self.conversation.type(
77
- f"usage: {command(self.configuration.command)} {subcommand('remove')} {input('[entity name]')} {hint('remove an entity from the project')}\n"
77
+ f"usage: {Colors.command(self.configuration.command)} {Colors.subcommand('remove')} {Colors.input('[entity name]')} {Colors.hint('remove an entity from the project')}\n"
78
78
  )
79
79
  self.conversation.newline()
80
80
  exit(1)
gibson/command/Schema.py CHANGED
@@ -1,8 +1,8 @@
1
1
  import sys
2
2
 
3
+ import gibson.core.Colors as Colors
3
4
  from gibson.api.Cli import Cli
4
5
  from gibson.command.BaseCommand import BaseCommand
5
- from gibson.core.Colors import argument, command, hint, subcommand
6
6
  from gibson.core.TimeKeeper import TimeKeeper
7
7
  from gibson.dev.Dev import Dev
8
8
 
@@ -12,7 +12,7 @@ class Schema(BaseCommand):
12
12
  if len(sys.argv) != 3:
13
13
  self.usage()
14
14
 
15
- self.configuration.ensure_project()
15
+ self.configuration.require_project()
16
16
  entity = self.memory.recall_stored_entity(sys.argv[2])
17
17
  if entity is None:
18
18
  self.conversation.not_sure_no_entity(
@@ -35,7 +35,7 @@ class Schema(BaseCommand):
35
35
  def usage(self):
36
36
  self.configuration.display_project()
37
37
  self.conversation.type(
38
- f"usage: {command(self.configuration.command)} {subcommand('schema')} {argument('[entity name]')} {hint('write the schema code for an entity')}\n"
38
+ f"usage: {Colors.command(self.configuration.command)} {Colors.subcommand('schema')} {Colors.argument('[entity name]')} {Colors.hint('write the schema code for an entity')}\n"
39
39
  )
40
40
  self.conversation.newline()
41
41
  exit(1)
gibson/command/Show.py CHANGED
@@ -1,19 +1,19 @@
1
1
  import sys
2
2
 
3
+ import gibson.core.Colors as Colors
3
4
  from gibson.command.BaseCommand import BaseCommand
4
- from gibson.core.Colors import argument, command, hint, subcommand
5
5
 
6
6
 
7
7
  class Show(BaseCommand):
8
8
  def execute(self):
9
9
  if len(sys.argv) == 2:
10
- self.configuration.ensure_project()
10
+ self.configuration.require_project()
11
11
  entities = self.memory.recall_merged()
12
12
  if entities is None:
13
13
  self.conversation.cant_no_entities(self.configuration.project.name)
14
14
  exit(1)
15
15
  elif len(sys.argv) == 3:
16
- self.configuration.ensure_project()
16
+ self.configuration.require_project()
17
17
  entity = self.memory.recall_entity(sys.argv[2])
18
18
  if entity is None:
19
19
  self.conversation.not_sure_no_entity(
@@ -25,16 +25,19 @@ class Show(BaseCommand):
25
25
  else:
26
26
  self.usage()
27
27
 
28
- for entity in entities:
29
- print(entity["definition"])
28
+ for entity in sorted(entities, key=lambda x: x["name"]):
29
+ statement = entity["definition"].replace(
30
+ entity["name"], Colors.argument(entity["name"])
31
+ )
32
+ print(f"\n{statement}")
30
33
 
31
34
  def usage(self):
32
35
  self.configuration.display_project()
33
36
  self.conversation.type(
34
- f"usage: {command(self.configuration.command)} {subcommand('show')} {hint('display the entire schema')}\n"
37
+ f"usage: {Colors.command(self.configuration.command)} {Colors.subcommand('show')} {Colors.hint('display the entire schema')}\n"
35
38
  )
36
39
  self.conversation.type(
37
- f" or: {command(self.configuration.command)} {subcommand('show')} {argument('[entity name]')} {hint('display the schema for an entity')}\n"
40
+ f" or: {Colors.command(self.configuration.command)} {Colors.subcommand('show')} {Colors.argument('[entity name]')} {Colors.hint('display the schema for an entity')}\n"
38
41
  )
39
42
  self.conversation.newline()
40
43
  exit(1)
gibson/command/Test.py CHANGED
@@ -1,8 +1,8 @@
1
1
  import sys
2
2
 
3
+ import gibson.core.Colors as Colors
3
4
  from gibson.api.Cli import Cli
4
5
  from gibson.command.BaseCommand import BaseCommand
5
- from gibson.core.Colors import argument, command, hint, subcommand
6
6
  from gibson.core.TimeKeeper import TimeKeeper
7
7
  from gibson.dev.Dev import Dev
8
8
 
@@ -12,7 +12,7 @@ class Test(BaseCommand):
12
12
  if len(sys.argv) != 3:
13
13
  self.usage()
14
14
 
15
- self.configuration.ensure_project()
15
+ self.configuration.require_project()
16
16
  entity = self.memory.recall_stored_entity(sys.argv[2])
17
17
  if entity is None:
18
18
  self.conversation.not_sure_no_entity(
@@ -35,7 +35,7 @@ class Test(BaseCommand):
35
35
  def usage(self):
36
36
  self.configuration.display_project()
37
37
  self.conversation.type(
38
- f"usage: {command(self.configuration.command)} {subcommand('test')} {argument('[entity name]')} {hint('write the unit tests for an entity')}\n"
38
+ f"usage: {Colors.command(self.configuration.command)} {Colors.subcommand('test')} {Colors.argument('[entity name]')} {Colors.hint('write the unit tests for an entity')}\n"
39
39
  )
40
40
  self.conversation.newline()
41
41
  exit(1)
gibson/command/Tree.py CHANGED
@@ -5,7 +5,7 @@ from .BaseCommand import BaseCommand
5
5
 
6
6
  class Tree(BaseCommand):
7
7
  def execute(self):
8
- self.configuration.ensure_project()
8
+ self.configuration.require_project()
9
9
  self.configuration.display_project()
10
10
 
11
11
  if self.configuration.project.dev.base.path is None:
gibson/command/Version.py CHANGED
@@ -1,8 +1,8 @@
1
1
  import requests
2
2
 
3
+ import gibson.core.Colors as Colors
3
4
  from gibson.command.BaseCommand import BaseCommand
4
5
  from gibson.conf.Version import Version as VersionConf
5
- from gibson.core.Colors import Color, colorize, command, option, subcommand
6
6
 
7
7
 
8
8
  class Version(BaseCommand):
@@ -15,18 +15,15 @@ class Version(BaseCommand):
15
15
 
16
16
  if latest_version != VersionConf.num:
17
17
  self.conversation.type(
18
- f"A new version of {command(self.configuration.command)} is available: {colorize(latest_version, Color.CYAN)}\n"
18
+ f"A new version of {Colors.command(self.configuration.command)} is available: {Colors.colorize(latest_version, Colors.Color.CYAN)}\n"
19
19
  )
20
20
  self.conversation.type(
21
- f"You are currently using version: {colorize(VersionConf.num, Color.VIOLET)}\n"
21
+ f"You are currently using version: {Colors.colorize(VersionConf.num, Colors.Color.VIOLET)}\n"
22
22
  )
23
23
  self.conversation.type(
24
- f"Please update to the latest version by running: {command('pip3')} {subcommand('install')} {option('--upgrade')} gibson-cli\n"
24
+ f"Please update to the latest version by running: {Colors.command('pip3')} {Colors.subcommand('install')} {Colors.option('--upgrade')} gibson-cli\n"
25
25
  )
26
26
  else:
27
27
  self.conversation.type(
28
- f"Nice! You are using the latest version of {command(self.configuration.command)}: {colorize(VersionConf.num, Color.CYAN)}\n"
28
+ f"Nice! 🎉 You are using the latest version of {Colors.command(self.configuration.command)}: {Colors.colorize(VersionConf.num, Colors.Color.CYAN)}\n"
29
29
  )
30
-
31
- self.conversation.newline()
32
- return True
@@ -1,9 +1,9 @@
1
1
  import sys
2
2
 
3
+ import gibson.core.Colors as Colors
3
4
  from gibson.command.auth.Login import Login
4
5
  from gibson.command.auth.Logout import Logout
5
6
  from gibson.command.BaseCommand import BaseCommand
6
- from gibson.core.Colors import argument, command, hint, subcommand
7
7
 
8
8
 
9
9
  class Auth(BaseCommand):
@@ -20,10 +20,10 @@ class Auth(BaseCommand):
20
20
  def usage(self):
21
21
  self.configuration.display_project()
22
22
  self.conversation.type(
23
- f"usage: {command(self.configuration.command)} {subcommand('auth')} {argument('login')} {hint('login to Gibson')}\n"
23
+ f"usage: {Colors.command(self.configuration.command)} {Colors.subcommand('auth')} {Colors.argument('login')} {Colors.hint('login to Gibson')}\n"
24
24
  )
25
25
  self.conversation.type(
26
- f" or: {command(self.configuration.command)} {subcommand('auth')} {argument('logout')} {hint('logout of Gibson')}\n"
26
+ f" or: {Colors.command(self.configuration.command)} {Colors.subcommand('auth')} {Colors.argument('logout')} {Colors.hint('logout of Gibson')}\n"
27
27
  )
28
28
  self.conversation.newline()
29
29
  exit(1)
@@ -0,0 +1,26 @@
1
+ import sys
2
+
3
+ import gibson.core.Colors as Colors
4
+ from gibson.command.BaseCommand import BaseCommand
5
+ from gibson.command.code.Entity import Entity
6
+
7
+
8
+ class Code(BaseCommand):
9
+ def execute(self):
10
+ if len(sys.argv) == 4 and sys.argv[2] == "entity":
11
+ Entity(self.configuration).execute()
12
+ else:
13
+ self.usage()
14
+
15
+ def usage(self):
16
+ self.configuration.display_project()
17
+ self.conversation.type(
18
+ f"usage: {Colors.command(self.configuration.command)} {Colors.subcommand('code')} {Colors.argument('entity')} {Colors.input('[entity name]')} {Colors.hint('create a new entity')}\n"
19
+ )
20
+ self.conversation.newline()
21
+ self.conversation.type(
22
+ ' To create a new entity named "user":\n'
23
+ f" {Colors.command(self.configuration.command)} {Colors.subcommand('code')} {Colors.argument('entity')} {Colors.input('user')}\n"
24
+ )
25
+ self.conversation.newline()
26
+ exit(1)
@@ -1,5 +1,4 @@
1
1
  import os
2
- import re
3
2
  import sys
4
3
  from string import Template
5
4
 
@@ -7,7 +6,6 @@ from gibson.api.Cli import Cli
7
6
  from gibson.command.BaseCommand import BaseCommand
8
7
  from gibson.command.Merge import Merge
9
8
  from gibson.command.rewrite.Rewrite import Rewrite
10
- from gibson.core.Colors import argument, command, hint, input, subcommand
11
9
  from gibson.core.Configuration import Configuration
12
10
  from gibson.display.Header import Header
13
11
  from gibson.display.WorkspaceFooter import WorkspaceFooter
@@ -18,7 +16,7 @@ from gibson.services.code.context.schema.Manager import (
18
16
  from gibson.structure.Entity import Entity
19
17
 
20
18
 
21
- class Code(BaseCommand):
19
+ class Entity(BaseCommand):
22
20
  CODE_WRITER_ENTITY_MODIFIER_NOOP = ""
23
21
 
24
22
  def __init__(self, configuration: Configuration):
@@ -82,12 +80,9 @@ class Code(BaseCommand):
82
80
  return Template(f.read()).substitute({"entity_name": sys.argv[3]})
83
81
 
84
82
  def execute(self):
85
- if len(sys.argv) != 4 or sys.argv[2] not in ["entity"]:
86
- self.usage()
87
-
88
83
  cli = Cli(self.configuration)
89
84
 
90
- self.configuration.ensure_project()
85
+ self.configuration.require_project()
91
86
  self.configuration.display_project()
92
87
  definition = self.configure_definition()
93
88
 
@@ -184,16 +179,3 @@ class Code(BaseCommand):
184
179
 
185
180
  print("")
186
181
  print(WorkspaceFooter().render())
187
-
188
- def usage(self):
189
- self.configuration.display_project()
190
- self.conversation.type(
191
- f"usage: {command(self.configuration.command)} {subcommand('code')} {argument('entity')} {input('[entity name]')} {hint('create a new entity')}\n"
192
- )
193
- self.conversation.newline()
194
- self.conversation.type(
195
- ' To create a new entity named "user":\n'
196
- f" {command(self.configuration.command)} {subcommand('code')} {argument('entity')} {input('user')}\n"
197
- )
198
- self.conversation.newline()
199
- exit(1)
@@ -1,16 +1,11 @@
1
1
  import sys
2
2
 
3
- from gibson.api.Cli import Cli
4
3
  from gibson.command.BaseCommand import BaseCommand
5
- from gibson.core.Colors import arguments, command, hint, subcommand
6
4
 
7
5
 
8
- class List(BaseCommand):
6
+ class Entities(BaseCommand):
9
7
  def execute(self):
10
- if len(sys.argv) != 3:
11
- self.usage()
12
-
13
- self.configuration.ensure_project()
8
+ self.configuration.require_project()
14
9
  self.configuration.display_project()
15
10
 
16
11
  entities = {"last": [], "stored": []}
@@ -54,11 +49,3 @@ class List(BaseCommand):
54
49
  self.conversation.newline()
55
50
 
56
51
  self.conversation.newline()
57
-
58
- def usage(self):
59
- self.configuration.display_project()
60
- self.conversation.type(
61
- f"usage: {command(self.configuration.command)} {subcommand('list')} {arguments(['entities'])} {hint('list all entities')}\n"
62
- )
63
- self.conversation.newline()
64
- exit(1)
@@ -0,0 +1,27 @@
1
+ import sys
2
+
3
+ import gibson.core.Colors as Colors
4
+ from gibson.command.BaseCommand import BaseCommand
5
+ from gibson.command.list.Entities import Entities
6
+ from gibson.command.list.Projects import Projects
7
+
8
+
9
+ class List(BaseCommand):
10
+ def execute(self):
11
+ if len(sys.argv) == 3 and sys.argv[2] == "entities":
12
+ Entities(self.configuration).execute()
13
+ elif len(sys.argv) == 3 and sys.argv[2] == "projects":
14
+ Projects(self.configuration).execute()
15
+ else:
16
+ self.usage()
17
+
18
+ def usage(self):
19
+ self.configuration.display_project()
20
+ self.conversation.type(
21
+ f"usage: {Colors.command(self.configuration.command)} {Colors.subcommand('list')} {Colors.arguments(['entities'])} {Colors.hint('list all entities')}\n"
22
+ )
23
+ self.conversation.type(
24
+ f" or: {Colors.command(self.configuration.command)} {Colors.subcommand('list')} {Colors.arguments(['projects'])} {Colors.hint('list all projects')}\n"
25
+ )
26
+ self.conversation.newline()
27
+ exit(1)
@@ -0,0 +1,25 @@
1
+ import re
2
+
3
+ import gibson.core.Colors as Colors
4
+ from gibson.api.ProjectApi import ProjectApi
5
+ from gibson.command.BaseCommand import BaseCommand
6
+
7
+
8
+ class Projects(BaseCommand):
9
+ def execute(self):
10
+ self.configuration.require_login()
11
+ projects = ProjectApi(self.configuration).all_projects()
12
+
13
+ self.conversation.type("Name".ljust(40))
14
+ self.conversation.type("ID")
15
+ self.conversation.newline()
16
+ self.conversation.type("----".ljust(40))
17
+ self.conversation.type("-" * 36)
18
+ self.conversation.newline()
19
+
20
+ for project in projects:
21
+ name = project["name"] if project["name"] is not None else "Untitled"
22
+ name = re.sub(r"^(.{36}).*$", "\g<1>...", name).ljust(40)
23
+ self.conversation.type(f"{Colors.command(name)}")
24
+ self.conversation.type(f"{project['uuid']}")
25
+ self.conversation.newline()
@@ -1,15 +1,17 @@
1
+ import gibson.core.Colors as Colors
1
2
  from gibson.api.Cli import Cli
2
3
  from gibson.command.BaseCommand import BaseCommand
3
- from gibson.core.Colors import argument, arguments, command, hint, subcommand
4
4
 
5
5
 
6
6
  class Module(BaseCommand):
7
7
  def execute(self):
8
- self.configuration.ensure_project()
8
+ self.configuration.require_project()
9
9
  module_name = self.conversation.prompt_module()
10
10
 
11
11
  self.conversation.newline()
12
- self.conversation.type(f"Generating new module: {argument(module_name)}\n")
12
+ self.conversation.type(
13
+ f"Generating new module: {Colors.argument(module_name)}\n"
14
+ )
13
15
 
14
16
  cli = Cli(self.configuration)
15
17
  response = cli.modeler_module(
@@ -22,7 +24,7 @@ class Module(BaseCommand):
22
24
 
23
25
  self.conversation.newline()
24
26
  self.conversation.type(
25
- f"The following entities were created in your {argument('last')} memory:\n"
27
+ f"The following entities were created in your {Colors.argument('last')} memory:\n"
26
28
  )
27
29
 
28
30
  for entity in response["entities"]:
@@ -32,7 +34,7 @@ class Module(BaseCommand):
32
34
  self.conversation.newline()
33
35
  self.conversation.type(f"If you want to persist these new entities run:\n")
34
36
  self.conversation.type(
35
- f"{command(self.configuration.command)} {subcommand('merge')}\n"
37
+ f"{Colors.command(self.configuration.command)} {Colors.subcommand('merge')}\n"
36
38
  )
37
39
 
38
40
  self.conversation.newline()
@@ -40,5 +42,5 @@ class Module(BaseCommand):
40
42
  f"Afterwards, you can modify any of these entities by running:\n"
41
43
  )
42
44
  self.conversation.type(
43
- f"{command(self.configuration.command)} {subcommand('modify')} {argument('[entity name]')} {input('[instructions]')}\n"
45
+ f"{Colors.command(self.configuration.command)} {Colors.subcommand('modify')} {Colors.argument('[entity name]')} {Colors.input('[instructions]')}\n"
44
46
  )
gibson/command/new/New.py CHANGED
@@ -1,9 +1,9 @@
1
1
  import sys
2
2
 
3
+ import gibson.core.Colors as Colors
3
4
  from gibson.command.BaseCommand import BaseCommand
4
5
  from gibson.command.new.Module import Module
5
6
  from gibson.command.new.Project import Project
6
- from gibson.core.Colors import argument, arguments, command, hint, subcommand
7
7
 
8
8
 
9
9
  class New(BaseCommand):
@@ -20,13 +20,13 @@ class New(BaseCommand):
20
20
  def usage(self):
21
21
  self.configuration.display_project()
22
22
  self.conversation.type(
23
- f"usage: {command(self.configuration.command)} {subcommand('new')} {arguments(['project', 'module'])} {hint('create something new')}\n"
23
+ f"usage: {Colors.command(self.configuration.command)} {Colors.subcommand('new')} {Colors.arguments(['project', 'module'])} {Colors.hint('create something new')}\n"
24
24
  )
25
25
  self.conversation.type(
26
- f" {command(self.configuration.command)} {subcommand('new')} {argument('project')} {hint('create a new project')}\n"
26
+ f" {Colors.command(self.configuration.command)} {Colors.subcommand('new')} {Colors.argument('project')} {Colors.hint('create a new project')}\n"
27
27
  )
28
28
  self.conversation.type(
29
- f" {command(self.configuration.command)} {subcommand('new')} {argument('module')} {hint('create a new module')}\n"
29
+ f" {Colors.command(self.configuration.command)} {Colors.subcommand('new')} {Colors.argument('module')} {Colors.hint('create a new module')}\n"
30
30
  )
31
31
  self.conversation.newline()
32
32
  exit(1)
@@ -3,27 +3,23 @@ import sys
3
3
  from gibson.api.Cli import Cli
4
4
  from gibson.command.BaseCommand import BaseCommand
5
5
  from gibson.command.rewrite.Rewrite import Rewrite
6
- from gibson.core.Colors import argument, command, hint, input, subcommand
7
6
 
8
7
 
9
- class Rename(BaseCommand):
8
+ class Entity(BaseCommand):
10
9
  def execute(self):
11
- if len(sys.argv) != 4:
12
- self.usage()
13
-
14
- self.configuration.ensure_project()
10
+ self.configuration.require_project()
15
11
  self.configuration.display_project()
16
12
 
17
- if self.memory.recall_entity(sys.argv[2]) is None:
13
+ if self.memory.recall_entity(sys.argv[3]) is None:
18
14
  self.conversation.type(
19
- f'Nothing renamed, did not find entity named "{sys.argv[2]}".\n'
15
+ f'Nothing renamed, did not find entity named "{sys.argv[3]}".\n'
20
16
  )
21
17
  self.conversation.newline()
22
18
  return self
23
19
 
24
- if self.memory.recall_entity(sys.argv[3]) is not None:
20
+ if self.memory.recall_entity(sys.argv[4]) is not None:
25
21
  self.conversation.type(
26
- f'Cannot rename to "{sys.argv[3]}" because that entity already exists.\n'
22
+ f'Cannot rename to "{sys.argv[4]}" because that entity already exists.\n'
27
23
  )
28
24
  self.conversation.newline()
29
25
  return self
@@ -35,8 +31,8 @@ class Rename(BaseCommand):
35
31
  response = cli.modeler_entity_rename(
36
32
  self.configuration.project.modeler.version,
37
33
  last["entities"],
38
- sys.argv[2],
39
34
  sys.argv[3],
35
+ sys.argv[4],
40
36
  )
41
37
 
42
38
  self.memory.remember_last({"entities": response["entities"]})
@@ -46,13 +42,13 @@ class Rename(BaseCommand):
46
42
  response = cli.modeler_entity_rename(
47
43
  self.configuration.project.modeler.version,
48
44
  stored,
49
- sys.argv[2],
50
45
  sys.argv[3],
46
+ sys.argv[4],
51
47
  )
52
48
 
53
49
  self.memory.remember_entities(response["entities"])
54
50
 
55
- self.conversation.type(f"[Renamed] {sys.argv[2]} -> {sys.argv[3]}\n")
51
+ self.conversation.type(f"[Renamed] {sys.argv[3]} -> {sys.argv[4]}\n")
56
52
  self.conversation.newline()
57
53
 
58
54
  Rewrite(self.configuration, header="Refactoring").write()
@@ -60,11 +56,3 @@ class Rename(BaseCommand):
60
56
  self.conversation.newline()
61
57
 
62
58
  return self
63
-
64
- def usage(self):
65
- self.configuration.display_project()
66
- self.conversation.type(
67
- f"usage: {command(self.configuration.command)} {subcommand('rename')} {argument('[current]')} {input('[new]')} {hint('rename an entity')}\n"
68
- )
69
- self.conversation.newline()
70
- exit(1)
@@ -0,0 +1,21 @@
1
+ import sys
2
+
3
+ import gibson.core.Colors as Colors
4
+ from gibson.command.BaseCommand import BaseCommand
5
+ from gibson.command.rename.Entity import Entity
6
+
7
+
8
+ class Rename(BaseCommand):
9
+ def execute(self):
10
+ if len(sys.argv) == 5 and sys.argv[2] == "entity":
11
+ Entity(self.configuration).execute()
12
+ else:
13
+ self.usage()
14
+
15
+ def usage(self):
16
+ self.configuration.display_project()
17
+ self.conversation.type(
18
+ f"usage: {Colors.command(self.configuration.command)} {Colors.subcommand('rename')} {Colors.argument('entity')} {Colors.input('[existing name]')} {Colors.input('[new name]')} {Colors.hint('rename an entity')}\n"
19
+ )
20
+ self.conversation.newline()
21
+ exit(1)
@@ -2,7 +2,7 @@ import os
2
2
  import shutil
3
3
  import sys
4
4
 
5
- from gibson.core.Colors import arguments, command, hint, subcommand
5
+ import gibson.core.Colors as Colors
6
6
  from gibson.core.Configuration import Configuration
7
7
  from gibson.core.TimeKeeper import TimeKeeper
8
8
  from gibson.services.code.customization.CustomizationManager import CustomizationManager
@@ -37,7 +37,7 @@ class Rewrite(BaseCommand):
37
37
  self.usage()
38
38
 
39
39
  def write(self, argument=None):
40
- self.configuration.ensure_project()
40
+ self.configuration.require_project()
41
41
 
42
42
  if len(self.memory.recall_merged()) == 0:
43
43
  self.conversation.cant_no_entities(self.configuration.project.name)
@@ -117,10 +117,10 @@ class Rewrite(BaseCommand):
117
117
  def usage(self):
118
118
  self.configuration.display_project()
119
119
  self.conversation.type(
120
- f"usage: {command(self.configuration.command)} {subcommand('rewrite')} {hint('rewrite all code')}\n"
120
+ f"usage: {Colors.command(self.configuration.command)} {Colors.subcommand('rewrite')} {Colors.hint('rewrite all code')}\n"
121
121
  )
122
122
  self.conversation.type(
123
- f" or: {command(self.configuration.command)} {subcommand('rewrite')} {arguments(self.arguments)} {hint('rewrite only the specified code')}\n"
123
+ f" or: {Colors.command(self.configuration.command)} {Colors.subcommand('rewrite')} {Colors.arguments(self.arguments)} {Colors.hint('rewrite only the specified code')}\n"
124
124
  )
125
125
  self.conversation.newline()
126
126
  exit(1)
@@ -2,14 +2,14 @@ import sys
2
2
 
3
3
  from gibson.command.auth.Auth import Auth
4
4
  from gibson.command.Build import Build
5
- from gibson.command.Code import Code
5
+ from gibson.command.code.Code import Code
6
6
  from gibson.command.Conf import Conf
7
7
  from gibson.command.Count import Count
8
8
  from gibson.command.Dev import Dev
9
9
  from gibson.command.Forget import Forget
10
10
  from gibson.command.Help import Help
11
11
  from gibson.command.Import import Import
12
- from gibson.command.List import List
12
+ from gibson.command.list.List import List
13
13
  from gibson.command.Merge import Merge
14
14
  from gibson.command.Model import Model
15
15
  from gibson.command.Modify import Modify
@@ -17,13 +17,8 @@ from gibson.command.new.New import New
17
17
  from gibson.command.OpenApi import OpenApi
18
18
  from gibson.command.Question import Question
19
19
  from gibson.command.Remove import Remove
20
- from gibson.command.Rename import Rename
21
- from gibson.command.rewrite.Api import Api
22
- from gibson.command.rewrite.Base import Base
23
- from gibson.command.rewrite.Models import Models
20
+ from gibson.command.rename.Rename import Rename
24
21
  from gibson.command.rewrite.Rewrite import Rewrite
25
- from gibson.command.rewrite.Schemas import Schemas
26
- from gibson.command.rewrite.Tests import Tests
27
22
  from gibson.command.Schema import Schema
28
23
  from gibson.command.Show import Show
29
24
  from gibson.command.Test import Test
@@ -248,7 +248,7 @@ class Configuration:
248
248
  return self
249
249
 
250
250
  def create_project_memory(self):
251
- self.ensure_project()
251
+ self.require_project()
252
252
  try:
253
253
  os.makedirs(self.project.paths.memory)
254
254
  except OSError as e:
@@ -259,17 +259,6 @@ class Configuration:
259
259
  if self.project is not None:
260
260
  self.conversation.display_project(self.project.name)
261
261
 
262
- def ensure_project(self):
263
- if self.project is None:
264
- self.conversation.gibsonai_project_not_set(self)
265
- exit(1)
266
-
267
- if self.project.name not in self.settings:
268
- self.conversation.unrecognized_project(self, self.project.name)
269
- exit(1)
270
-
271
- return self
272
-
273
262
  def get_access_token(self):
274
263
  try:
275
264
  with open(f"{self.paths.auth}/{self.API_ENV}", "r") as f:
@@ -281,7 +270,7 @@ class Configuration:
281
270
  return token["access_token"]
282
271
 
283
272
  def get_my_settings(self):
284
- self.ensure_project()
273
+ self.require_project()
285
274
  return self.settings[self.project.name]
286
275
 
287
276
  def get_refresh_token(self):
@@ -358,6 +347,24 @@ class Configuration:
358
347
 
359
348
  return self
360
349
 
350
+ def require_login(self):
351
+ if self.get_access_token() is None:
352
+ self.conversation.message_login_required()
353
+ exit(1)
354
+
355
+ return self
356
+
357
+ def require_project(self):
358
+ if self.project is None:
359
+ self.conversation.gibsonai_project_not_set(self)
360
+ exit(1)
361
+
362
+ if self.project.name not in self.settings:
363
+ self.conversation.unrecognized_project(self, self.project.name)
364
+ exit(1)
365
+
366
+ return self
367
+
361
368
  def set_auth_tokens(self, access_token, refresh_token):
362
369
  try:
363
370
  os.mkdir(self.paths.auth)
@@ -439,7 +446,7 @@ class Configuration:
439
446
  return self
440
447
 
441
448
  def turn_dev_off(self):
442
- self.ensure_project()
449
+ self.require_project()
443
450
  self.settings[self.project.name]["dev"]["active"] = False
444
451
  self.write_config()
445
452
  return self
@@ -447,7 +454,7 @@ class Configuration:
447
454
  def turn_dev_on(
448
455
  self, api_path, api_prefix, api_version, base_path, model_path, schema_path
449
456
  ):
450
- self.ensure_project()
457
+ self.require_project()
451
458
  self.settings[self.project.name]["dev"]["active"] = True
452
459
  self.settings[self.project.name]["dev"]["api"]["path"] = api_path
453
460
  self.settings[self.project.name]["dev"]["api"]["prefix"] = api_prefix
@@ -5,8 +5,8 @@ import time
5
5
 
6
6
  import pyfiglet
7
7
 
8
+ import gibson.core.Colors as Colors
8
9
  from gibson.conf.Version import Version
9
- from gibson.core.Colors import project
10
10
 
11
11
 
12
12
  class Conversation:
@@ -74,7 +74,7 @@ class Conversation:
74
74
  self.newline()
75
75
 
76
76
  def display_project(self, project_name):
77
- self.type(f"<> Project {project(project_name)}\n\n")
77
+ self.type(f"<> Project {Colors.project(project_name)}\n\n")
78
78
 
79
79
  def entities_hijacked(self):
80
80
  self.type(
@@ -130,6 +130,13 @@ class Conversation:
130
130
  self.type("Login failed, please try again.\n")
131
131
  return self
132
132
 
133
+ def message_login_required(self):
134
+ self.type("You need to login before performing this action.\n")
135
+ self.type(
136
+ f"Run {Colors.command('gibson')} {Colors.subcommand('auth')} {Colors.argument('login')} and try again.\n"
137
+ )
138
+ return self
139
+
133
140
  def message_login_success(self):
134
141
  self.newline()
135
142
  self.type("Nice! You're now logged in.\n")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: gibson-cli
3
- Version: 0.5.2
3
+ Version: 0.5.4
4
4
  Summary: Gibson Command Line Interface
5
5
  Author-email: GibsonAI <noc@gibsonai.com>
6
6
  Project-URL: Homepage, https://gibsonai.com/
@@ -1,41 +1,46 @@
1
1
  bin/build.sh,sha256=H3TAd349BECbcK3_t_jW9VzoLInMNrXtaLnXMEVanew,49
2
2
  bin/release.sh,sha256=LxPqH5kxhLKvzHaPRLBlq_ApaK7FHEteH4SzeRenidk,49
3
- gibson/api/BaseApi.py,sha256=l_EsHdKRz-cXGXd3Ju5IFwmCRUkunba6ckB957S9DAk,2696
4
- gibson/api/Cli.py,sha256=JlioOwE3oob_OY_cr6qis0QEINU1H68ZjkWEQiGhZ-4,7897
3
+ gibson/api/BaseApi.py,sha256=DYSo_AcJUwZ0NSsqeJbEorKa3LRQwU4EVqvoISRHvk8,2924
4
+ gibson/api/Cli.py,sha256=KvlMDvcMh7i6p3yGeikGmfi4HjUWb49RncJyF-J-9lM,7752
5
+ gibson/api/ProjectApi.py,sha256=T7TqtywJjrzFIfARenQUsrH-80x9Oo1pABbFAdlQkI0,356
5
6
  gibson/bin/gibson.py,sha256=N1mAWaww9pw8s5u0et87FC5cFHVU6JzN4Kls3lDn-xw,354
6
7
  gibson/command/BaseCommand.py,sha256=mmWUO0FxjMCbv3cHWnnasfAWnU_hTuGHUsRVJ4hUcqM,777
7
- gibson/command/Build.py,sha256=eypLUpZb3bw9LJ3s4uANZNbMNhshj90g94iQTreY74w,2851
8
- gibson/command/Code.py,sha256=Tb-eVAODHAbTqQldC2vR30YhrQvM2CtsiXt34RUoS3I,6913
9
- gibson/command/Conf.py,sha256=z7G-81GpPUGZxjuE0HJn3ltHBIScqy4-rzinLYCyiLA,2467
10
- gibson/command/Count.py,sha256=FInot7Wz-lClKM1gfKgZXwBVIsTR0Gde0cMjYrCitog,1086
11
- gibson/command/Dev.py,sha256=KXaWeAMGifrxb4uyBJ5W0v9XIYeG8_C1Dw8TiAeOlHE,4358
12
- gibson/command/Forget.py,sha256=2-XpPqzjqhdGvilMitZECVBegDzlV12kDiR0xrxEVyY,1064
8
+ gibson/command/Build.py,sha256=KWGaTBF-_uChOmXQsaZChq--nXc4xJPpLfOG8K89vME,2849
9
+ gibson/command/Conf.py,sha256=MbEPT-lRujRJMBjKRQlshA3T3pplQ-zzia8RY_muWU4,2472
10
+ gibson/command/Count.py,sha256=Jh9_ImJibpiTitbllSl0xF6KUrOhrY7Bz7-5sx9cBVs,1083
11
+ gibson/command/Dev.py,sha256=-kmRHpOApUXklaCs4bJVqCRft4ubcVjAL7S1-BGr-ps,4355
12
+ gibson/command/Forget.py,sha256=5fszuq6oIe0unMbXpFtDpouJ1eYZIvsi2mLsa8RwN5U,1061
13
13
  gibson/command/Help.py,sha256=KoHukpEk_jLNxaNdM-n4R-dXj_VZub6x4xIXbTK1_wU,4794
14
- gibson/command/Import.py,sha256=4VeDtQNWf20j2tSvAMjU9r-gB05fD3hh6Mfxdp5B_oI,4174
15
- gibson/command/List.py,sha256=XNL0p3WvGCjuWeFD_24VO5d2sflXfkk_CvAbXrcOMYI,2318
16
- gibson/command/Merge.py,sha256=AKhyImy_MH8sy7m9Anh1SKBINvLrRmt91fFE4oVPg7k,1060
17
- gibson/command/Model.py,sha256=rare94DN7Cij4IizBscwl6TBQvQy_RkVt8SgnUBZW1I,1278
18
- gibson/command/Modify.py,sha256=jYx8ojVoecPAX_YasvpGGqq2d0dl2FfCB3WAlSxtdtM,1269
19
- gibson/command/OpenApi.py,sha256=mdjgzDgJTu8aMuI1bojExEAstCQuFzhFCnutNSm9z14,4313
20
- gibson/command/Question.py,sha256=KHFDLI3ItIFg3Qeeamy_zaXSZQyFBXdl3LEr4iq8FOg,3986
21
- gibson/command/Remove.py,sha256=i-ofK_uQfkgrP63vYaBxDTIhzs_-4p0FFaqd3f4fJvo,2435
22
- gibson/command/Rename.py,sha256=VUp8vrj3ugOG9i6CgXw8putbZAUsSw6iC8J1FBB05nQ,2245
23
- gibson/command/Schema.py,sha256=NAOp6RY4apSArPE7ZljT150AIQjpm88C6N_SRIophWo,1291
24
- gibson/command/Show.py,sha256=lGwguywp1lk4-E1T8iMFQR39mqir2rUqNXZES7H4WO4,1405
25
- gibson/command/Test.py,sha256=O0Ro3o_SAtNf0y7VwrVS7b2hrJ_sA-UepOxnfp8MEN4,1285
26
- gibson/command/Tree.py,sha256=pqVbebySThqJ-29izerScwaIb4XE40K3cYNA8bUpNkE,3055
27
- gibson/command/Version.py,sha256=LA162K8oPDJAwPEja6ppoHVU8tr7shA1gzkcWxV4XVs,1282
14
+ gibson/command/Import.py,sha256=fD-PNsRk5qaOWmdmgLdFJ97wCYJDNFXzmHw_e68Lcv0,4216
15
+ gibson/command/Merge.py,sha256=R5ybMC1tUR5_T8YyUfXutzFa_V9j1_flv0s7KTJRq0M,1061
16
+ gibson/command/Model.py,sha256=eRAAvklZjXgstGbM-P9QeG85YQ80TRVZyYTIzzUPzsk,1279
17
+ gibson/command/Modify.py,sha256=3_fEGvLfGpgoXQ77SFA9J2KQDe1GMaAUPWkl-yCwR1E,1267
18
+ gibson/command/OpenApi.py,sha256=G1LGfco0PgMIBw4C_ksja2_0nKKnZzUoiNl2iY64QKw,4314
19
+ gibson/command/Question.py,sha256=8mWumOFKBeS_Lw8_4vF6eDIEx3kdbIwz11mLtY6e9zo,3998
20
+ gibson/command/Remove.py,sha256=mDDpfQV3ggppGSFf9v09exdr2ZG_Qat60CjSBwcvX4A,2436
21
+ gibson/command/Schema.py,sha256=zg10N6uHL37CHQRx8fH00kKS6loSS9kpFe_yv1K6-j8,1289
22
+ gibson/command/Show.py,sha256=5fzNtDJvnQm7-w8fbF8vu6pmH31vugVDEVi_VgRXRQ0,1586
23
+ gibson/command/Test.py,sha256=HBwroaudQ1BSEsRDbv8MOOUiwXFjJgCUNnSFUi6uX3s,1283
24
+ gibson/command/Tree.py,sha256=BeJ_13xrrRCK5FP2rQHWpDKrshVzte-_D1pNG1GXPIw,3056
25
+ gibson/command/Version.py,sha256=YLd2c9eiVT6Xzj-ulRuL9QSiu21Fid2Jp_B7nD6k86o,1267
28
26
  gibson/command/WarGames.py,sha256=V0KIpz-Z546qtQaOPdIVHQ6wp2n3r3M3tgKx-GRQzzU,1300
29
- gibson/command/auth/Auth.py,sha256=JScajZ__oSo24jzFa5NccCgc4yKgxn0BI0dXPWE5bA4,1000
27
+ gibson/command/auth/Auth.py,sha256=rkWhAast68jL-_XVRU-3mIx2_ntlgmAJuwYx37gNVEI,1025
30
28
  gibson/command/auth/Login.py,sha256=b43OfV76i6aGdOwj1NK64ZOdYlNyc08g3lZGQ_37KDw,437
31
29
  gibson/command/auth/Logout.py,sha256=V01q4TdbiBqCnIrM6IA4T25fO6ws0UpXp42I3pwHZVM,248
32
- gibson/command/new/Module.py,sha256=XTbfdWKiccEfuqjcCA2Fg1kfl2ngbHGjDhCrbTvevi4,1562
33
- gibson/command/new/New.py,sha256=o-LMZurujp6cp01xKCdHY02F0hakXG3N7qkxKm-ZN58,1214
30
+ gibson/command/code/Code.py,sha256=9LUrenkSr51WjVaP11ebvKvgjs9fOl8ase-A6OS2aPE,977
31
+ gibson/command/code/Entity.py,sha256=R-R4URE5XKkLN2oxsBSrkAmx3edO9FryYzTMxkDC6WQ,6170
32
+ gibson/command/list/Entities.py,sha256=4qUxR5pBsUwnaW3SZQzCVbwyl_sCfM9lD9TWwipSyWw,1869
33
+ gibson/command/list/List.py,sha256=r6YQdaeMRgFKcz-VyEQTE_I2lRaaJ4kew3E_RKKaaTU,1047
34
+ gibson/command/list/Projects.py,sha256=FAPahdzMs-zkr43ULtrPmo_3OOxtoCnaASyJ9h5iJlU,899
35
+ gibson/command/new/Module.py,sha256=MFbE4XY7YZz0I-SfxHxWe4FYiJHBssI2knATy1yuqs0,1599
36
+ gibson/command/new/New.py,sha256=yAES_nhiZcv3Jo9kb2E_YfAiVAcnRoeE6Ftd1PqQbQ8,1256
34
37
  gibson/command/new/Project.py,sha256=sExmNYDKWMIohAoBiF73nkVubgy6iMleaknXW8fWZJA,657
38
+ gibson/command/rename/Entity.py,sha256=SaAiN1bYsTOsqjyVzxghK8-N3sAKITThTzS5LEYgppY,1801
39
+ gibson/command/rename/Rename.py,sha256=T6iTjo6KRArbT8wBgrn-ehtNlY7tRlovlEZfBOUKYlk,731
35
40
  gibson/command/rewrite/Api.py,sha256=sSvAqEJXdgQjYcu0uiM6ndHE3GnfkfVL6eqP2Otkbww,1002
36
41
  gibson/command/rewrite/Base.py,sha256=YJ2a5Hl0f9NXHUBBPvlt-dUIqEPWQz5vH6-1EHmbFbA,640
37
42
  gibson/command/rewrite/Models.py,sha256=eoUpZHpR0qwNgX60EWfcNz49GHmBw_FGfBuHH2ueZqY,799
38
- gibson/command/rewrite/Rewrite.py,sha256=jaoaruSCsOazZmDAytv9GD2YBrnBSonWO4jOd9C1B10,4666
43
+ gibson/command/rewrite/Rewrite.py,sha256=2v5xhb6JYv-I7jF7B5CpQbw7KWBFHnXLWK5mMaL-N8k,4684
39
44
  gibson/command/rewrite/Schemas.py,sha256=zZ1gjmOJg77gh70t5y2WkzHWSAvEKx5-gqRN9OcsCXA,802
40
45
  gibson/command/rewrite/Tests.py,sha256=HO1WM6pSToVKsuJn7nUA_I5qrfBN0cgKgBzjlm2Qxt8,799
41
46
  gibson/command/tests/test_command_BaseCommand.py,sha256=hSbBfLFI3RTp_DdEHtm5oOLWoN6drI6ucFJypi7xxV8,364
@@ -59,10 +64,10 @@ gibson/conf/dev/Schema.py,sha256=kOSlX1jEyVb82xd8TO8jEAimLcaefIFJr6d2JYvyTqg,74
59
64
  gibson/conf/tests/test_conf_Dependencies.py,sha256=LITeeYiqXM5rKkyWFBqcnMvUR5pzDRuHVAngH372jWc,116
60
65
  gibson/conf/tests/test_conf_Platform.py,sha256=Zc53IsZmV-hT9VRrZEPNrsuehSdWnJXWKGMmOhEqWHo,138
61
66
  gibson/core/Colors.py,sha256=5XJdm9n5Sa75Hv0BYVaGVhnzsgpwfbB2pGXcbGh5EjU,1539
62
- gibson/core/CommandRouter.py,sha256=_CN9BVHDbBMy-o0RJ4NjZ8rHbZolqSEKYwWLCNRBMMw,3999
67
+ gibson/core/CommandRouter.py,sha256=96Y38GvY14BtBNfb3LwBz-T0_qscyeo51q6xDxVjto0,3781
63
68
  gibson/core/Completions.py,sha256=Bsh25vnf0pjpJA6MJNR_2MA2s58Ujj8XolR8fm8AQ_s,1197
64
- gibson/core/Configuration.py,sha256=rJq6XFS-vV8elACYmbFdnzzW4PsQb1BjyWuajfx46KQ,15787
65
- gibson/core/Conversation.py,sha256=FjDeaDy7xZqSlY3Sb1VZlAyRnycjSR_8t9-84TvNcsM,8993
69
+ gibson/core/Configuration.py,sha256=aKELMA524DULG4P7ynrlNGRM9KodLIJDuA39FPRINng,15962
70
+ gibson/core/Conversation.py,sha256=ExZvefcbBZH69z0aYvQ9aLItnG_1v6EtZ6mK5h5_QYg,9275
66
71
  gibson/core/Env.py,sha256=08dZRHzzR0ahrbM4S0bXC7V1xhYQkT8Zefs00qUHf0U,498
67
72
  gibson/core/Memory.py,sha256=Yw6xmqtAsFwd5Q4VgmGDt4U2dUGLyFXZ_nO8c74Oo8E,4005
68
73
  gibson/core/PythonPath.py,sha256=p1q7n_5KnPvA8XbxJyvqC2vrIdEdTiMr6vRU9yj77Cs,1567
@@ -108,8 +113,8 @@ gibson/structure/tests/test_Entity.py,sha256=Gl9f1NcEKdpWCx4W3takFFzp18mLhCYWKrd
108
113
  gibson/tests/test_Env.py,sha256=DPWmP0-aEelducq9bAwv7rKoY2NjWXUeCrzfJDQkn2M,369
109
114
  gibson/tests/test_Memory.py,sha256=YP7owToABAk_-s7fD5UG0HTc4lamDjdA39JUlLnk3Fg,2574
110
115
  gibson/tests/test_utils.py,sha256=r_y-EG05YTCNtL8MWiAK1KmPsmeoMgypKsQC_lVgOtM,559
111
- gibson_cli-0.5.2.dist-info/METADATA,sha256=jMUs0Mfz7ffTyq0b4SQ-AsTqlSvFKCsuzagox03Lzvw,11605
112
- gibson_cli-0.5.2.dist-info/WHEEL,sha256=UvcQYKBHoFqaQd6LKyqHw9fxEolWLQnlzP0h_LgJAfI,91
113
- gibson_cli-0.5.2.dist-info/entry_points.txt,sha256=j5VUvq3AzL21xPvVC24zMoXFt-I5lUWulr66nL3OAPM,50
114
- gibson_cli-0.5.2.dist-info/top_level.txt,sha256=RFaUY7VXGiqkMwo1Rj7pM4kGvxkhhnfo-2LmPpuL_fs,11
115
- gibson_cli-0.5.2.dist-info/RECORD,,
116
+ gibson_cli-0.5.4.dist-info/METADATA,sha256=_4GEBjQAXRdXxote3GwcNk7JCyDGCfxLo_dPuJY3Vck,11605
117
+ gibson_cli-0.5.4.dist-info/WHEEL,sha256=cVxcB9AmuTcXqmwrtPhNK88dr7IR_b6qagTj0UvIEbY,91
118
+ gibson_cli-0.5.4.dist-info/entry_points.txt,sha256=j5VUvq3AzL21xPvVC24zMoXFt-I5lUWulr66nL3OAPM,50
119
+ gibson_cli-0.5.4.dist-info/top_level.txt,sha256=RFaUY7VXGiqkMwo1Rj7pM4kGvxkhhnfo-2LmPpuL_fs,11
120
+ gibson_cli-0.5.4.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (74.0.0)
2
+ Generator: setuptools (74.1.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5