gibson-cli 0.1.6__tar.gz → 0.3.0__tar.gz

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 (120) hide show
  1. {gibson_cli-0.1.6/gibson_cli.egg-info → gibson_cli-0.3.0}/PKG-INFO +1 -1
  2. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/api/BaseApi.py +9 -26
  3. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/api/Cli.py +2 -2
  4. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/command/Code.py +2 -2
  5. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/command/Import.py +2 -2
  6. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/command/Remove.py +2 -2
  7. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/command/Rename.py +2 -2
  8. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/command/Version.py +2 -1
  9. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/command/auth/Auth.py +5 -2
  10. gibson_cli-0.3.0/gibson/command/auth/Login.py +13 -0
  11. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/command/auth/Logout.py +1 -0
  12. {gibson_cli-0.1.6/gibson/command → gibson_cli-0.3.0/gibson/command/rewrite}/Base.py +0 -5
  13. {gibson_cli-0.1.6/gibson/command → gibson_cli-0.3.0/gibson/command/rewrite}/Models.py +0 -4
  14. gibson_cli-0.3.0/gibson/command/rewrite/Rewrite.py +124 -0
  15. {gibson_cli-0.1.6/gibson/command → gibson_cli-0.3.0/gibson/command/rewrite}/Schemas.py +1 -5
  16. {gibson_cli-0.1.6/gibson/command → gibson_cli-0.3.0/gibson/command/rewrite}/Tests.py +1 -5
  17. gibson_cli-0.3.0/gibson/core/Colors.py +64 -0
  18. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/core/CommandRouter.py +8 -38
  19. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/core/Configuration.py +43 -3
  20. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/core/Conversation.py +22 -3
  21. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/data/bash-completion.tmpl +12 -9
  22. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/lang/Python.py +5 -3
  23. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/lang/tests/test_lang_Python.py +2 -7
  24. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/services/code/customization/Authenticator.py +1 -1
  25. {gibson_cli-0.1.6 → gibson_cli-0.3.0/gibson_cli.egg-info}/PKG-INFO +1 -1
  26. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson_cli.egg-info/SOURCES.txt +7 -6
  27. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/pyproject.toml +1 -1
  28. gibson_cli-0.1.6/gibson/command/Rewrite.py +0 -107
  29. gibson_cli-0.1.6/gibson/command/auth/Login.py +0 -20
  30. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/.gitignore +0 -0
  31. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/.pre-commit-config.yaml +0 -0
  32. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/README.md +0 -0
  33. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/bin/build.sh +0 -0
  34. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/bin/release.sh +0 -0
  35. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/bin/gibson.py +0 -0
  36. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/command/BaseCommand.py +0 -0
  37. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/command/Build.py +0 -0
  38. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/command/Conf.py +0 -0
  39. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/command/Count.py +0 -0
  40. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/command/Dev.py +0 -0
  41. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/command/Forget.py +0 -0
  42. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/command/List.py +0 -0
  43. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/command/Merge.py +0 -0
  44. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/command/Model.py +0 -0
  45. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/command/Modify.py +0 -0
  46. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/command/Module.py +0 -0
  47. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/command/New.py +0 -0
  48. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/command/OpenApi.py +0 -0
  49. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/command/Question.py +0 -0
  50. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/command/Schema.py +0 -0
  51. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/command/Show.py +0 -0
  52. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/command/Test.py +0 -0
  53. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/command/Tree.py +0 -0
  54. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/command/WarGames.py +0 -0
  55. {gibson_cli-0.1.6/gibson/command → gibson_cli-0.3.0/gibson/command/rewrite}/Api.py +0 -0
  56. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/command/tests/test_command_BaseCommand.py +0 -0
  57. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/command/tests/test_command_Conf.py +0 -0
  58. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/conf/Api.py +0 -0
  59. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/conf/Code.py +0 -0
  60. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/conf/Custom.py +0 -0
  61. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/conf/Datastore.py +0 -0
  62. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/conf/Dependencies.py +0 -0
  63. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/conf/Dev.py +0 -0
  64. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/conf/Frameworks.py +0 -0
  65. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/conf/Modeler.py +0 -0
  66. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/conf/Paths.py +0 -0
  67. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/conf/Platform.py +0 -0
  68. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/conf/Project.py +0 -0
  69. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/conf/Version.py +0 -0
  70. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/conf/dev/Api.py +0 -0
  71. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/conf/dev/Base.py +0 -0
  72. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/conf/dev/Model.py +0 -0
  73. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/conf/dev/Schema.py +0 -0
  74. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/conf/tests/test_conf_Dependencies.py +0 -0
  75. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/conf/tests/test_conf_Platform.py +0 -0
  76. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/core/Completions.py +0 -0
  77. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/core/Env.py +0 -0
  78. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/core/Memory.py +0 -0
  79. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/core/TimeKeeper.py +0 -0
  80. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/core/utils.py +0 -0
  81. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/data/default-ref-table.tmpl +0 -0
  82. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/data/default-table.tmpl +0 -0
  83. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/db/TableExceptions.py +0 -0
  84. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/db/tests/test_db_TableExceptions.py +0 -0
  85. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/dev/Dev.py +0 -0
  86. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/display/Header.py +0 -0
  87. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/display/WorkspaceFooter.py +0 -0
  88. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/display/WorkspaceHeader.py +0 -0
  89. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/display/tests/test_display_Header.py +0 -0
  90. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/display/tests/test_display_WorkspaceFooter.py +0 -0
  91. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/display/tests/test_display_WorkspaceHeader.py +0 -0
  92. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/services/auth/Server.py +0 -0
  93. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/services/code/context/schema/DataDictionary.py +0 -0
  94. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/services/code/context/schema/EntityKeys.py +0 -0
  95. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/services/code/context/schema/Manager.py +0 -0
  96. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/services/code/context/schema/tests/test_code_context_schema_DataDictionary.py +0 -0
  97. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/services/code/context/schema/tests/test_code_context_schema_EntityKeys.py +0 -0
  98. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/services/code/context/schema/tests/test_code_context_schema_Manager.py +0 -0
  99. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/services/code/customization/BaseCustomization.py +0 -0
  100. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/services/code/customization/CustomizationManager.py +0 -0
  101. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/services/code/customization/tests/test_code_customization_Authenticator.py +0 -0
  102. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/services/code/customization/tests/test_code_customization_BaseCustomization.py +0 -0
  103. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/structure/Entity.py +0 -0
  104. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/structure/constraints/ReferenceConstraint.py +0 -0
  105. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/structure/keys/ForeignKey.py +0 -0
  106. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/structure/keys/Index.py +0 -0
  107. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/structure/keys/IndexAttribute.py +0 -0
  108. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/structure/keys/tests/test_ForeignKey.py +0 -0
  109. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/structure/keys/tests/test_Index.py +0 -0
  110. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/structure/keys/tests/test_IndexAttribute.py +0 -0
  111. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/structure/testing.py +0 -0
  112. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/structure/tests/test_Entity.py +0 -0
  113. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/tests/test_Env.py +0 -0
  114. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/tests/test_Memory.py +0 -0
  115. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson/tests/test_utils.py +0 -0
  116. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson_cli.egg-info/dependency_links.txt +0 -0
  117. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson_cli.egg-info/entry_points.txt +0 -0
  118. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/gibson_cli.egg-info/top_level.txt +0 -0
  119. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/requirements.txt +0 -0
  120. {gibson_cli-0.1.6 → gibson_cli-0.3.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: gibson-cli
3
- Version: 0.1.6
3
+ Version: 0.3.0
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,18 @@
1
1
  import os
2
+
2
3
  import requests
3
4
 
4
5
  from gibson.core.Configuration import Configuration
5
6
 
6
7
 
7
8
  class BaseApi:
8
- API_ENV = os.environ.get("GIBSONAI_API_ENV", "staging")
9
9
  VERSION = "v1"
10
10
 
11
11
  def __init__(self, configuration: Configuration):
12
12
  self.configuration = configuration
13
13
 
14
- def api_domain(self):
15
- domains = {
16
- "local": "http://localhost:8000",
17
- "staging": "https://staging-api.gibsonai.com",
18
- "production": "https://api.gibsonai.com",
19
- }
20
- return domains[self.API_ENV]
21
-
22
- def app_domain(self):
23
- domains = {
24
- "local": "http://localhost:5173",
25
- "staging": "https://staging-app.gibsonai.com",
26
- "production": "https://app.gibsonai.com",
27
- }
28
- return domains[self.API_ENV]
29
-
30
14
  def base_url(self):
31
- return f"{self.api_domain()}/{self.VERSION}"
32
-
33
- def client_id(self):
34
- return {
35
- "local": "9b0cbebd-3eb4-47be-89ac-4aa589316ff4",
36
- "staging": "02459e16-f356-4c01-b689-59847ed04b0a",
37
- "production": "da287371-240b-4b53-bfde-4b1581cca62a",
38
- }[self.API_ENV]
15
+ return f"{self.configuration.api_domain()}/{self.VERSION}"
39
16
 
40
17
  def get(self, endpoint):
41
18
  r = requests.get(self.url(endpoint), headers=self.headers())
@@ -82,6 +59,7 @@ class BaseApi:
82
59
  )
83
60
 
84
61
  if r.status_code != 200:
62
+ self.configuration.set_auth_tokens(None, None)
85
63
  return False
86
64
 
87
65
  parsed = r.json()
@@ -96,12 +74,17 @@ class BaseApi:
96
74
  return f"{self.base_url()}/{endpoint}"
97
75
 
98
76
  def __raise_for_status(self, r):
77
+ if r.status_code == 401:
78
+ print("\n\nYou need to log in to continue. Please run:\n")
79
+ print(" gibson auth login\n\n")
80
+ print("and then try again.\n")
81
+ exit(1)
82
+
99
83
  try:
100
84
  r.raise_for_status()
101
85
  except:
102
86
  try:
103
87
  message = r.json()
104
-
105
88
  print("=" * 78)
106
89
  print("Raw Response:\n")
107
90
  print(message)
@@ -1,6 +1,6 @@
1
1
  from gibson.core.Configuration import Configuration
2
- from gibson.lang.Python import Python
3
2
  from gibson.core.Memory import Memory
3
+ from gibson.lang.Python import Python
4
4
 
5
5
  from .BaseApi import BaseApi
6
6
 
@@ -61,7 +61,7 @@ class Cli(BaseApi):
61
61
 
62
62
  def headers(self):
63
63
  headers = {
64
- "X-Gibson-Client-ID": self.client_id(),
64
+ "X-Gibson-Client-ID": self.configuration.client_id(),
65
65
  "X-Gibson-API-Key": self.configuration.project.api.key,
66
66
  }
67
67
 
@@ -6,7 +6,7 @@ from string import Template
6
6
  from gibson.api.Cli import Cli
7
7
  from gibson.command.BaseCommand import BaseCommand
8
8
  from gibson.command.Merge import Merge
9
- from gibson.command.Rewrite import Rewrite
9
+ from gibson.command.rewrite.Rewrite import Rewrite
10
10
  from gibson.core.Configuration import Configuration
11
11
  from gibson.display.Header import Header
12
12
  from gibson.display.WorkspaceFooter import WorkspaceFooter
@@ -129,7 +129,7 @@ class Code(BaseCommand):
129
129
  Merge(self.configuration).execute()
130
130
  self.conversation.unmute()
131
131
 
132
- Rewrite(self.configuration, wipe=False).execute()
132
+ Rewrite(self.configuration, wipe=False).write()
133
133
 
134
134
  self.conversation.newline()
135
135
 
@@ -5,7 +5,7 @@ from sqlalchemy.orm import sessionmaker
5
5
 
6
6
  from gibson.api.Cli import Cli
7
7
  from gibson.command.BaseCommand import BaseCommand
8
- from gibson.command.Rewrite import Rewrite
8
+ from gibson.command.rewrite.Rewrite import Rewrite
9
9
  from gibson.db.TableExceptions import TableExceptions
10
10
 
11
11
 
@@ -48,7 +48,7 @@ class Import(BaseCommand):
48
48
  self.conversation.newline()
49
49
 
50
50
  if write_code:
51
- Rewrite(self.configuration).execute()
51
+ Rewrite(self.configuration).write()
52
52
  self.conversation.newline()
53
53
 
54
54
  return True
@@ -2,7 +2,7 @@ import sys
2
2
 
3
3
  from gibson.api.Cli import Cli
4
4
  from gibson.command.BaseCommand import BaseCommand
5
- from gibson.command.Rewrite import Rewrite
5
+ from gibson.command.rewrite.Rewrite import Rewrite
6
6
 
7
7
 
8
8
  class Remove(BaseCommand):
@@ -63,7 +63,7 @@ class Remove(BaseCommand):
63
63
  self.conversation.type(f"[Removed] {sys.argv[2]}\n")
64
64
  self.conversation.newline()
65
65
 
66
- Rewrite(self.configuration, header="Refactoring").execute()
66
+ Rewrite(self.configuration, header="Refactoring").write()
67
67
 
68
68
  self.conversation.newline()
69
69
 
@@ -2,7 +2,7 @@ import sys
2
2
 
3
3
  from gibson.api.Cli import Cli
4
4
  from gibson.command.BaseCommand import BaseCommand
5
- from gibson.command.Rewrite import Rewrite
5
+ from gibson.command.rewrite.Rewrite import Rewrite
6
6
 
7
7
 
8
8
  class Rename(BaseCommand):
@@ -53,7 +53,7 @@ class Rename(BaseCommand):
53
53
  self.conversation.type(f"[Renamed] {sys.argv[2]} -> {sys.argv[3]}\n")
54
54
  self.conversation.newline()
55
55
 
56
- Rewrite(self.configuration, header="Refactoring").execute()
56
+ Rewrite(self.configuration, header="Refactoring").write()
57
57
 
58
58
  self.conversation.newline()
59
59
 
@@ -4,5 +4,6 @@ from gibson.conf.Version import Version as VersionConf
4
4
 
5
5
  class Version(BaseCommand):
6
6
  def execute(self):
7
- self.conversation.type(VersionConf.num)
7
+ self.conversation.type(f"{VersionConf.num}\n")
8
+ self.conversation.newline()
8
9
  return True
@@ -3,6 +3,7 @@ import sys
3
3
  from gibson.command.auth.Login import Login
4
4
  from gibson.command.auth.Logout import Logout
5
5
  from gibson.command.BaseCommand import BaseCommand
6
+ from gibson.core.Colors import argument, command, hint, subcommand
6
7
 
7
8
 
8
9
  class Auth(BaseCommand):
@@ -18,8 +19,10 @@ class Auth(BaseCommand):
18
19
 
19
20
  def usage(self):
20
21
  self.conversation.type(
21
- f"usage: {self.configuration.command} auth login\n"
22
- + f" or: {self.configuration.command} auth logout\n"
22
+ f"usage: {command(self.configuration.command)} {subcommand('auth')} {argument('login')} {hint('login to Gibson')} \n"
23
+ )
24
+ self.conversation.type(
25
+ f" or: {command(self.configuration.command)} {subcommand('auth')} {argument('logout')} {hint('logout of Gibson')}\n"
23
26
  )
24
27
  self.conversation.newline()
25
28
  exit(1)
@@ -0,0 +1,13 @@
1
+ from gibson.api.BaseApi import BaseApi
2
+ from gibson.command.BaseCommand import BaseCommand
3
+ from gibson.services.auth.Server import Server as AuthServer
4
+
5
+
6
+ class Login(BaseCommand):
7
+ def execute(self):
8
+ authenticated = self.configuration.login()
9
+ if authenticated:
10
+ self.conversation.message_login_success()
11
+ else:
12
+ self.conversation.message_login_failure()
13
+ self.conversation.newline()
@@ -5,3 +5,4 @@ class Logout(BaseCommand):
5
5
  def execute(self):
6
6
  self.configuration.set_access_token(None)
7
7
  self.conversation.type(f"You are now logged out.")
8
+ self.conversation.newline()
@@ -6,11 +6,6 @@ from gibson.dev.Dev import Dev
6
6
 
7
7
  class Base(BaseCommand):
8
8
  def execute(self):
9
- entities = self.memory.recall_merged()
10
- if len(entities) == 0:
11
- self.conversation.cant_no_entities(self.configuration.project.name)
12
- exit(1)
13
-
14
9
  time_keeper = TimeKeeper()
15
10
  dev = Dev(self.configuration)
16
11
 
@@ -11,10 +11,6 @@ class Models(BaseCommand):
11
11
  for entity in self.memory.entities:
12
12
  entities.append(entity["name"])
13
13
 
14
- if len(entities) == 0:
15
- self.conversation.cant_no_entities(self.configuration.project.name)
16
- exit(1)
17
-
18
14
  time_keeper = TimeKeeper()
19
15
 
20
16
  cli = Cli(self.configuration)
@@ -0,0 +1,124 @@
1
+ import os
2
+ import shutil
3
+ import sys
4
+
5
+ from gibson.core.Colors import arguments, command, hint, subcommand
6
+ from gibson.core.Configuration import Configuration
7
+ from gibson.core.TimeKeeper import TimeKeeper
8
+ from gibson.services.code.customization.CustomizationManager import CustomizationManager
9
+
10
+ from ..BaseCommand import BaseCommand
11
+ from .Api import Api
12
+ from .Base import Base
13
+ from .Models import Models
14
+ from .Schemas import Schemas
15
+ from .Tests import Tests
16
+
17
+
18
+ class Rewrite(BaseCommand):
19
+ def __init__(
20
+ self,
21
+ configuration: Configuration,
22
+ header="Writing Code",
23
+ wipe=True,
24
+ with_header=False,
25
+ ):
26
+ super().__init__(configuration)
27
+ self.wipe = wipe
28
+ self.with_header = with_header
29
+ self.arguments = ["api", "base", "models", "schemas", "tests"]
30
+
31
+ def execute(self):
32
+ if len(sys.argv) != 3:
33
+ self.write()
34
+ elif sys.argv[2] in self.arguments:
35
+ self.write(sys.argv[2])
36
+ else:
37
+ self.usage()
38
+
39
+ def write(self, argument=None):
40
+ if len(self.memory.recall_merged()) == 0:
41
+ self.conversation.cant_no_entities(self.configuration.project.name)
42
+ exit(1)
43
+
44
+ if self.with_header is True:
45
+ self.conversation.display_project(self.configuration.project.name)
46
+
47
+ customization_manager = CustomizationManager(self.configuration).preserve()
48
+
49
+ try:
50
+ if self.wipe is True:
51
+ for root, dirs, files in os.walk(
52
+ os.path.expandvars(self.configuration.project.dev.base.path)
53
+ ):
54
+ for file in files:
55
+ os.unlink(os.path.join(root, file))
56
+
57
+ for dir_ in dirs:
58
+ shutil.rmtree(os.path.join(root, dir_))
59
+
60
+ self.conversation.type("Writing Code\n")
61
+
62
+ if argument is None or argument == "api":
63
+ time_keeper = TimeKeeper()
64
+ self.conversation.type(" API ")
65
+ self.conversation.mute()
66
+ # Disable customization management here so we don't process this twice (see finally block)
67
+ Api(self.configuration).disable_customization_management().execute()
68
+ self.conversation.unmute()
69
+ self.conversation.type(time_keeper.get_display())
70
+ self.conversation.newline()
71
+
72
+ if argument is None or argument == "base":
73
+ time_keeper = TimeKeeper()
74
+ self.conversation.type(" Base ")
75
+ self.conversation.mute()
76
+ Base(self.configuration).execute()
77
+ self.conversation.unmute()
78
+ self.conversation.type(time_keeper.get_display())
79
+ self.conversation.newline()
80
+
81
+ if argument is None or argument == "models":
82
+ time_keeper = TimeKeeper()
83
+ self.conversation.type(" Models ")
84
+ self.conversation.mute()
85
+ Models(self.configuration).execute()
86
+ self.conversation.unmute()
87
+ self.conversation.type(time_keeper.get_display())
88
+ self.conversation.newline()
89
+
90
+ if argument is None or argument == "schemas":
91
+ time_keeper = TimeKeeper()
92
+ self.conversation.type(" Schemas ")
93
+ self.conversation.mute()
94
+ Schemas(self.configuration).execute()
95
+ self.conversation.unmute()
96
+ self.conversation.type(time_keeper.get_display())
97
+ self.conversation.newline()
98
+
99
+ if argument is None or argument == "tests":
100
+ time_keeper = TimeKeeper()
101
+ self.conversation.type(" Tests ")
102
+ self.conversation.mute()
103
+ Tests(self.configuration).execute()
104
+ self.conversation.unmute()
105
+ self.conversation.type(time_keeper.get_display())
106
+ self.conversation.newline()
107
+ finally:
108
+ customization_manager.restore()
109
+
110
+ if self.with_header is True:
111
+ self.conversation.newline()
112
+
113
+ return self
114
+
115
+ def usage(self):
116
+ self.conversation.display_project(self.configuration.project.name)
117
+ self.conversation.type(
118
+ f"usage: {command(self.configuration.command)} {subcommand('rewrite')} {hint('rewrite all code')} \n"
119
+ )
120
+ self.conversation.type(
121
+ f" or: {command(self.configuration.command)} {subcommand('rewrite')} {arguments(self.arguments)} {hint('rewrite only the specified code')}\n"
122
+ )
123
+ self.conversation.newline()
124
+ exit(1)
@@ -1,7 +1,7 @@
1
1
  from gibson.api.Cli import Cli
2
- from gibson.dev.Dev import Dev
3
2
  from gibson.command.BaseCommand import BaseCommand
4
3
  from gibson.core.TimeKeeper import TimeKeeper
4
+ from gibson.dev.Dev import Dev
5
5
 
6
6
 
7
7
  class Schemas(BaseCommand):
@@ -11,10 +11,6 @@ class Schemas(BaseCommand):
11
11
  for entity in self.memory.entities:
12
12
  entities.append(entity["name"])
13
13
 
14
- if len(entities) == 0:
15
- self.conversation.cant_no_entities(self.configuration.project.name)
16
- exit(1)
17
-
18
14
  time_keeper = TimeKeeper()
19
15
 
20
16
  cli = Cli(self.configuration)
@@ -1,7 +1,7 @@
1
1
  from gibson.api.Cli import Cli
2
- from gibson.dev.Dev import Dev
3
2
  from gibson.command.BaseCommand import BaseCommand
4
3
  from gibson.core.TimeKeeper import TimeKeeper
4
+ from gibson.dev.Dev import Dev
5
5
 
6
6
 
7
7
  class Tests(BaseCommand):
@@ -11,10 +11,6 @@ class Tests(BaseCommand):
11
11
  for entity in self.memory.entities:
12
12
  entities.append(entity["name"])
13
13
 
14
- if len(entities) == 0:
15
- self.conversation.cant_no_entities(self.configuration.project.name)
16
- exit(1)
17
-
18
14
  time_keeper = TimeKeeper()
19
15
 
20
16
  cli = Cli(self.configuration)
@@ -0,0 +1,64 @@
1
+ class Color:
2
+ BLACK = "\033[30m"
3
+ BLACK_BG = "\033[40m"
4
+ BLINK = "\033[5m"
5
+ BLINK2 = "\033[6m"
6
+ BLUE = "\033[34m"
7
+ BLUE_BG = "\033[44m"
8
+ BLUE_BG2 = "\033[104m"
9
+ BLUE2 = "\033[94m"
10
+ BOLD = "\033[1m"
11
+ CYAN = "\033[36m"
12
+ CYAN_BG = "\033[46m"
13
+ CYAN_BG2 = "\033[106m"
14
+ CYAN2 = "\033[96m"
15
+ END = "\033[0m"
16
+ GREEN = "\033[32m"
17
+ GREEN_BG = "\033[42m"
18
+ GREEN_BG2 = "\033[102m"
19
+ GREEN2 = "\033[92m"
20
+ GREY = "\033[90m"
21
+ GREY_BG = "\033[100m"
22
+ ITALIC = "\033[3m"
23
+ RED = "\033[31m"
24
+ RED_BG = "\033[41m"
25
+ RED_BG2 = "\033[101m"
26
+ RED2 = "\033[91m"
27
+ SELECTED = "\033[7m"
28
+ UNDERLINE = "\033[4m"
29
+ VIOLET = "\033[35m"
30
+ VIOLET_BG = "\033[45m"
31
+ VIOLET_BG2 = "\033[105m"
32
+ VIOLET2 = "\033[95m"
33
+ WHITE = "\033[37m"
34
+ WHITE_BG = "\033[47m"
35
+ WHITE_BG2 = "\033[107m"
36
+ WHITE2 = "\033[97m"
37
+ YELLOW = "\033[33m"
38
+ YELLOW_BG = "\033[43m"
39
+ YELLOW_BG2 = "\033[103m"
40
+ YELLOW2 = "\033[93m"
41
+
42
+
43
+ def colorize(text, color):
44
+ return f"{color}{text}{Color.END}"
45
+
46
+
47
+ def command(text):
48
+ return colorize(text, Color.GREEN)
49
+
50
+
51
+ def subcommand(text):
52
+ return colorize(text, Color.YELLOW)
53
+
54
+
55
+ def argument(text):
56
+ return colorize(text, Color.VIOLET)
57
+
58
+
59
+ def arguments(list):
60
+ return f"[{'|'.join(map(lambda x: argument(x), list))}]"
61
+
62
+
63
+ def hint(text):
64
+ return colorize(text, Color.GREY)
@@ -1,8 +1,6 @@
1
1
  import sys
2
2
 
3
- from gibson.command.Api import Api
4
3
  from gibson.command.auth.Auth import Auth
5
- from gibson.command.Base import Base
6
4
  from gibson.command.Build import Build
7
5
  from gibson.command.Code import Code
8
6
  from gibson.command.Conf import Conf
@@ -13,7 +11,6 @@ from gibson.command.Import import Import
13
11
  from gibson.command.List import List
14
12
  from gibson.command.Merge import Merge
15
13
  from gibson.command.Model import Model
16
- from gibson.command.Models import Models
17
14
  from gibson.command.Modify import Modify
18
15
  from gibson.command.Module import Module
19
16
  from gibson.command.New import New
@@ -21,12 +18,15 @@ from gibson.command.OpenApi import OpenApi
21
18
  from gibson.command.Question import Question
22
19
  from gibson.command.Remove import Remove
23
20
  from gibson.command.Rename import Rename
24
- from gibson.command.Rewrite import Rewrite
21
+ from gibson.command.rewrite.Api import Api
22
+ from gibson.command.rewrite.Base import Base
23
+ from gibson.command.rewrite.Models import Models
24
+ from gibson.command.rewrite.Rewrite import Rewrite
25
+ from gibson.command.rewrite.Schemas import Schemas
26
+ from gibson.command.rewrite.Tests import Tests
25
27
  from gibson.command.Schema import Schema
26
- from gibson.command.Schemas import Schemas
27
28
  from gibson.command.Show import Show
28
29
  from gibson.command.Test import Test
29
- from gibson.command.Tests import Tests
30
30
  from gibson.command.Tree import Tree
31
31
  from gibson.command.Version import Version
32
32
  from gibson.command.WarGames import WarGames
@@ -49,18 +49,10 @@ class CommandRouter:
49
49
  dev_on = "*"
50
50
 
51
51
  commands = {
52
- "api": {
53
- "description": "write the API code for the project",
54
- "memory": "stored",
55
- },
56
52
  "auth": {
57
53
  "description": "login | logout",
58
54
  "memory": None,
59
55
  },
60
- "base": {
61
- "description": "write the base code for the project",
62
- "memory": "stored",
63
- },
64
56
  "build": {
65
57
  "description": "create the entities in the datastore",
66
58
  "memory": "stored",
@@ -96,10 +88,6 @@ class CommandRouter:
96
88
  "description": "write the model code for an entity",
97
89
  "memory": "stored",
98
90
  },
99
- "models": {
100
- "description": "write all the model code",
101
- "memory": "stored",
102
- },
103
91
  "modify": {
104
92
  "description": "change an entity using natural language",
105
93
  "memory": "last > stored",
@@ -116,26 +104,18 @@ class CommandRouter:
116
104
  "memory": "last > stored",
117
105
  },
118
106
  "rewrite": {
119
- "description": "rewrite all code from scratch",
107
+ "description": "rewrite code",
120
108
  "memory": "stored",
121
109
  },
122
110
  "schema": {
123
111
  "description": "write the schema code for an entity",
124
112
  "memory": "stored",
125
113
  },
126
- "schemas": {
127
- "description": "write all the schema code",
128
- "memory": "stored",
129
- },
130
114
  "show": {"description": "display an entity", "memory": "last > stored"},
131
115
  "test": {
132
116
  "description": "write the unit tests for an entity",
133
117
  "memory": "stored",
134
118
  },
135
- "tests": {
136
- "description": "write all the unit tests",
137
- "memory": "stored",
138
- },
139
119
  "tree": {"description": "illustrate the project layout", "memory": None},
140
120
  "? | q": {"description": "ask a question", "memory": None},
141
121
  }
@@ -187,12 +167,8 @@ class CommandRouter:
187
167
  Env().verify(self.configuration)
188
168
 
189
169
  command = None
190
- if sys.argv[1] == "api":
191
- command = Api(self.configuration)
192
- elif sys.argv[1] == "auth":
170
+ if sys.argv[1] == "auth":
193
171
  command = Auth(self.configuration)
194
- elif sys.argv[1] == "base":
195
- command = Base(self.configuration)
196
172
  elif sys.argv[1] == "build":
197
173
  command = Build(self.configuration)
198
174
  elif sys.argv[1] == "code":
@@ -213,8 +189,6 @@ class CommandRouter:
213
189
  command = Merge(self.configuration)
214
190
  elif sys.argv[1] == "model":
215
191
  command = Model(self.configuration)
216
- elif sys.argv[1] == "models":
217
- command = Models(self.configuration)
218
192
  elif sys.argv[1] == "modify":
219
193
  command = Modify(self.configuration)
220
194
  elif sys.argv[1] == "module":
@@ -231,14 +205,10 @@ class CommandRouter:
231
205
  command = Rewrite(self.configuration, with_header=True)
232
206
  elif sys.argv[1] == "schema":
233
207
  command = Schema(self.configuration)
234
- elif sys.argv[1] == "schemas":
235
- command = Schemas(self.configuration)
236
208
  elif sys.argv[1] == "show":
237
209
  command = Show(self.configuration)
238
210
  elif sys.argv[1] == "test":
239
211
  command = Test(self.configuration)
240
- elif sys.argv[1] == "tests":
241
- command = Tests(self.configuration)
242
212
  elif sys.argv[1] == "tree":
243
213
  command = Tree(self.configuration)
244
214
  elif sys.argv[1] in ["?", "q"]: