gibson-cli 0.1.0__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 (102) hide show
  1. api/BaseApi.py +45 -0
  2. api/Cli.py +248 -0
  3. bin/gibson.py +16 -0
  4. command/Api.py +31 -0
  5. command/Base.py +28 -0
  6. command/BaseCommand.py +26 -0
  7. command/Build.py +69 -0
  8. command/Code.py +198 -0
  9. command/Conf.py +74 -0
  10. command/Count.py +35 -0
  11. command/Dev.py +121 -0
  12. command/Forget.py +34 -0
  13. command/Import.py +109 -0
  14. command/List.py +61 -0
  15. command/Merge.py +35 -0
  16. command/Model.py +42 -0
  17. command/Models.py +31 -0
  18. command/Modify.py +43 -0
  19. command/Module.py +42 -0
  20. command/New.py +38 -0
  21. command/OpenApi.py +141 -0
  22. command/Question.py +105 -0
  23. command/Remove.py +80 -0
  24. command/Rename.py +71 -0
  25. command/Rewrite.py +107 -0
  26. command/Schema.py +42 -0
  27. command/Schemas.py +31 -0
  28. command/Show.py +37 -0
  29. command/Test.py +42 -0
  30. command/Tests.py +31 -0
  31. command/Tree.py +92 -0
  32. command/WarGames.py +35 -0
  33. command/auth/Auth.py +25 -0
  34. command/auth/Login.py +17 -0
  35. command/auth/Logout.py +7 -0
  36. command/tests/test_command_BaseCommand.py +10 -0
  37. command/tests/test_command_Conf.py +19 -0
  38. conf/Api.py +3 -0
  39. conf/Code.py +9 -0
  40. conf/Custom.py +4 -0
  41. conf/Datastore.py +4 -0
  42. conf/Dependencies.py +24 -0
  43. conf/Dev.py +15 -0
  44. conf/Frameworks.py +7 -0
  45. conf/Modeler.py +3 -0
  46. conf/Paths.py +10 -0
  47. conf/Platform.py +16 -0
  48. conf/Project.py +18 -0
  49. conf/Version.py +2 -0
  50. conf/dev/Api.py +5 -0
  51. conf/dev/Base.py +3 -0
  52. conf/dev/Model.py +3 -0
  53. conf/dev/Schema.py +3 -0
  54. conf/tests/test_conf_Dependencies.py +5 -0
  55. conf/tests/test_conf_Platform.py +7 -0
  56. core/CommandRouter.py +249 -0
  57. core/Configuration.py +418 -0
  58. core/Conversation.py +270 -0
  59. core/Env.py +12 -0
  60. core/Memory.py +148 -0
  61. core/TimeKeeper.py +12 -0
  62. core/utils.py +19 -0
  63. data/default-ref-table.tmpl +4 -0
  64. data/default-table.tmpl +6 -0
  65. db/TableExceptions.py +6 -0
  66. db/tests/test_db_TableExceptions.py +9 -0
  67. dev/Dev.py +92 -0
  68. display/Header.py +6 -0
  69. display/WorkspaceFooter.py +10 -0
  70. display/WorkspaceHeader.py +8 -0
  71. display/tests/test_display_Header.py +9 -0
  72. display/tests/test_display_WorkspaceFooter.py +9 -0
  73. display/tests/test_display_WorkspaceHeader.py +8 -0
  74. gibson_cli-0.1.0.dist-info/METADATA +306 -0
  75. gibson_cli-0.1.0.dist-info/RECORD +102 -0
  76. gibson_cli-0.1.0.dist-info/WHEEL +5 -0
  77. gibson_cli-0.1.0.dist-info/entry_points.txt +2 -0
  78. gibson_cli-0.1.0.dist-info/top_level.txt +12 -0
  79. lang/Python.py +57 -0
  80. lang/tests/test_lang_Python.py +70 -0
  81. services/auth/Server.py +75 -0
  82. services/code/context/schema/DataDictionary.py +12 -0
  83. services/code/context/schema/EntityKeys.py +49 -0
  84. services/code/context/schema/Manager.py +28 -0
  85. services/code/context/schema/tests/test_code_context_schema_DataDictionary.py +8 -0
  86. services/code/context/schema/tests/test_code_context_schema_EntityKeys.py +52 -0
  87. services/code/context/schema/tests/test_code_context_schema_Manager.py +34 -0
  88. services/code/customization/Authenticator.py +51 -0
  89. services/code/customization/BaseCustomization.py +12 -0
  90. services/code/customization/CustomizationManager.py +20 -0
  91. services/code/customization/tests/test_code_customization_Authenticator.py +53 -0
  92. services/code/customization/tests/test_code_customization_BaseCustomization.py +14 -0
  93. structure/Entity.py +115 -0
  94. structure/constraints/ReferenceConstraint.py +36 -0
  95. structure/keys/ForeignKey.py +41 -0
  96. structure/keys/Index.py +64 -0
  97. structure/keys/IndexAttribute.py +14 -0
  98. structure/keys/tests/test_ForeignKey.py +80 -0
  99. structure/keys/tests/test_Index.py +98 -0
  100. structure/keys/tests/test_IndexAttribute.py +17 -0
  101. structure/testing.py +194 -0
  102. structure/tests/test_Entity.py +107 -0
command/Conf.py ADDED
@@ -0,0 +1,74 @@
1
+ import sys
2
+
3
+ from .BaseCommand import BaseCommand
4
+
5
+
6
+ class Conf(BaseCommand):
7
+ def __compile_configuration_keys(self, element, setting, keys):
8
+ if not isinstance(element, dict):
9
+ keys.append("::".join(setting))
10
+ else:
11
+ for key, value in element.items():
12
+ if key not in ["dev", "modeler"]:
13
+ self.__compile_configuration_keys(
14
+ element[key], setting + [key], keys
15
+ )
16
+
17
+ return keys
18
+
19
+ def execute(self):
20
+ if len(sys.argv) != 4 or sys.argv[2] not in self.get_configuration_keys():
21
+ self.usage()
22
+
23
+ settings = self.configuration.get_my_settings()
24
+ key = sys.argv[2]
25
+ value = sys.argv[3]
26
+ item = settings
27
+
28
+ elements = key.split("::")
29
+ for i in range(len(elements) - 1):
30
+ try:
31
+ item = item[elements[i]]
32
+ except KeyError:
33
+ self.usage()
34
+
35
+ try:
36
+ old_value = item[elements[-1]]
37
+ item[elements[-1]] = value
38
+ except KeyError:
39
+ self.usage()
40
+
41
+ self.conversation.display_project(self.configuration.project.name)
42
+ self.conversation.type(f"{key}\n")
43
+ self.conversation.type(f" [old value] {old_value}\n")
44
+ self.conversation.type(f" [new value] {value}\n")
45
+ self.conversation.newline()
46
+ self.configuration.write_config()
47
+
48
+ return self
49
+
50
+ def get_configuration_keys(self):
51
+ configuration_keys = self.__compile_configuration_keys(
52
+ self.configuration.get_my_settings(), [], []
53
+ )
54
+
55
+ del configuration_keys[configuration_keys.index("meta::version")]
56
+
57
+ return configuration_keys
58
+
59
+ def usage(self):
60
+ self.conversation.display_project(self.configuration.project.name)
61
+ self.conversation.type(
62
+ f"usage: {self.configuration.command} conf [key] [value]\n"
63
+ " where [key] is one of:\n"
64
+ )
65
+ self.conversation.set_delay(0.004)
66
+
67
+ for key in self.get_configuration_keys():
68
+ self.conversation.type(f" {key}\n")
69
+
70
+ self.conversation.newline()
71
+ self.conversation.type('"That was recursive! I used recursion, guys!"\n')
72
+ self.conversation.type(" -- Montero, 02/06/2024\n")
73
+ self.conversation.newline()
74
+ exit(1)
command/Count.py ADDED
@@ -0,0 +1,35 @@
1
+ import sys
2
+
3
+ from .BaseCommand import BaseCommand
4
+
5
+
6
+ class Count(BaseCommand):
7
+ def execute(self):
8
+ if len(sys.argv) != 3 or sys.argv[2] not in ["last", "stored"]:
9
+ self.usage()
10
+
11
+ if sys.argv[2] == "last":
12
+ count = 0
13
+ if self.memory.last is not None:
14
+ count = len(self.memory.last["entities"])
15
+
16
+ print(count)
17
+ elif sys.argv[2] == "stored":
18
+ count = 0
19
+ if self.memory.entities is not None:
20
+ count = len(self.memory.entities)
21
+
22
+ print(count)
23
+ else:
24
+ raise NotImplementedError
25
+
26
+ return self
27
+
28
+ def usage(self):
29
+ self.conversation.display_project(self.configuration.project.name)
30
+ self.conversation.type(
31
+ f"usage: {self.configuration.command} count [which memory]\n"
32
+ + ' where [which memory] is one of "last" or "stored"\n'
33
+ )
34
+ self.conversation.newline()
35
+ exit(1)
command/Dev.py ADDED
@@ -0,0 +1,121 @@
1
+ import os
2
+ import sys
3
+
4
+ from lang.Python import Python
5
+
6
+ from .BaseCommand import BaseCommand
7
+
8
+
9
+ class Dev(BaseCommand):
10
+ def __display_language_specific_instructions(self):
11
+ if self.configuration.project.code.language == "python":
12
+ pythonpath = Python().define_python_path(
13
+ [
14
+ os.path.expandvars(self.configuration.project.dev.base.path),
15
+ os.path.expandvars(self.configuration.project.dev.model.path),
16
+ os.path.expandvars(self.configuration.project.dev.schema.path),
17
+ ]
18
+ )
19
+ if pythonpath is not None:
20
+ self.conversation.type(
21
+ "Your Python environment needs to be configured, so do this:\n"
22
+ )
23
+ self.conversation.type(
24
+ f" export PYTHONPATH=$PYTHONPATH:{pythonpath}\n\n"
25
+ )
26
+
27
+ return self
28
+
29
+ def execute(self):
30
+ if len(sys.argv) != 3 or sys.argv[2] not in ["off", "on"]:
31
+ self.usage()
32
+
33
+ if sys.argv[2] == "off":
34
+ if self.configuration.project.dev.active is True:
35
+ self.configuration.turn_dev_off()
36
+
37
+ self.off()
38
+
39
+ self.conversation.display_project(self.configuration.project.name)
40
+ self.conversation.type(
41
+ "Leveling up. Nice! I need a little context to make sure I write "
42
+ + "code\nin the correct place. Then I will need you to tell me "
43
+ + "about how to\nconfigure the API.\n\n"
44
+ )
45
+
46
+ api_path = self.configuration.project.dev.api.path
47
+ if api_path is None:
48
+ api_path = ""
49
+
50
+ base_path = self.configuration.project.dev.base.path
51
+ if base_path is None:
52
+ base_path = ""
53
+
54
+ model_path = self.configuration.project.dev.model.path
55
+ if model_path is None:
56
+ model_path = ""
57
+
58
+ schema_path = self.configuration.project.dev.schema.path
59
+ if schema_path is None:
60
+ schema_path = ""
61
+
62
+ self.conversation.type(
63
+ " I need a writable directory into which I can put code.\n"
64
+ )
65
+ base = self.configuration.ask_for_path(base_path)
66
+
67
+ for subdir in ["api", "model", "schema"]:
68
+ try:
69
+ os.mkdir(f"{os.path.expandvars(base)}/{subdir}")
70
+ except FileExistsError:
71
+ pass
72
+
73
+ self.conversation.type(
74
+ "\n https://api.yourdomain.com/v1/-/sneakers GET\n", delay=0.002
75
+ )
76
+ self.conversation.type(" ^ ^\n", delay=0.002)
77
+ self.conversation.type(" | |\n", delay=0.002)
78
+ self.conversation.type(" version _| |\n", delay=0.002)
79
+ self.conversation.type(
80
+ " |_ prefix (to isolate GibsonAI "
81
+ + "API routes)\n\n",
82
+ delay=0.002,
83
+ )
84
+ self.conversation.type(
85
+ " It is OK if you are not sure about these. Just leave the defaults\n"
86
+ + " and when you make a decision I will rewrite the code for you.\n\n"
87
+ )
88
+
89
+ api_version = self.configuration.ask_for_value(
90
+ " version", self.configuration.project.dev.api.version
91
+ )
92
+ api_prefix = self.configuration.ask_for_value(
93
+ " prefix", self.configuration.project.dev.api.prefix
94
+ )
95
+
96
+ self.configuration.turn_dev_on(
97
+ f"{base}/api",
98
+ api_prefix,
99
+ api_version,
100
+ base,
101
+ f"{base}/model",
102
+ f"{base}/schema",
103
+ )
104
+
105
+ self.conversation.newline()
106
+ self.__display_language_specific_instructions()
107
+ self.conversation.type("Dev Mode is on!\n\n")
108
+
109
+ return self
110
+
111
+ def off(self):
112
+ self.conversation.display_project(self.configuration.project.name)
113
+ self.conversation.type("Dev Mode is off!\n")
114
+ self.conversation.newline()
115
+ exit(1)
116
+
117
+ def usage(self):
118
+ self.conversation.display_project(self.configuration.project.name)
119
+ self.conversation.type(f"usage: {self.configuration.command} dev [off | on]\n")
120
+ self.conversation.newline()
121
+ exit(1)
command/Forget.py ADDED
@@ -0,0 +1,34 @@
1
+ import sys
2
+
3
+ from .BaseCommand import BaseCommand
4
+
5
+
6
+ class Forget(BaseCommand):
7
+ def execute(self):
8
+ if len(sys.argv) != 3 or sys.argv[2] not in ["all", "last", "stored"]:
9
+ self.usage()
10
+
11
+ if sys.argv[2] == "all":
12
+ self.memory.forget_last()
13
+ self.memory.forget_entities()
14
+ elif sys.argv[2] == "last":
15
+ self.memory.forget_last()
16
+ elif sys.argv[2] == "stored":
17
+ self.memory.forget_entities()
18
+ else:
19
+ raise NotImplementedError
20
+
21
+ self.conversation.display_project(self.configuration.project.name)
22
+ self.conversation.type("Yeah man, forgotten.\n")
23
+ self.conversation.newline()
24
+
25
+ return self
26
+
27
+ def usage(self):
28
+ self.conversation.display_project(self.configuration.project.name)
29
+ self.conversation.type(
30
+ f"usage: {self.configuration.command} forget [which memory]\n"
31
+ + ' where [which memory] is one of "all", "last" or "stored"\n'
32
+ )
33
+ self.conversation.newline()
34
+ exit(1)
command/Import.py ADDED
@@ -0,0 +1,109 @@
1
+ import sys
2
+
3
+ from sqlalchemy import create_engine
4
+ from sqlalchemy.orm import sessionmaker
5
+
6
+ from api.Cli import Cli
7
+ from db.TableExceptions import TableExceptions
8
+
9
+ from .BaseCommand import BaseCommand
10
+ from .Rewrite import Rewrite
11
+
12
+
13
+ class Import(BaseCommand):
14
+ def execute(self):
15
+ if len(sys.argv) != 3 and len(sys.argv) != 5:
16
+ self.usage()
17
+
18
+ write_code = False
19
+ if len(sys.argv) == 5:
20
+ if sys.argv[3] != ".." or sys.argv[4] != "dev":
21
+ self.usage()
22
+
23
+ if self.configuration.project.dev.active is False:
24
+ self.conversation.display_project(self.configuration.project.name)
25
+ self.conversation.type(
26
+ "Dude, seriously?! You have Dev Mode turned off. "
27
+ + "Why would you do that?\n"
28
+ )
29
+ self.conversation.newline()
30
+ exit(1)
31
+
32
+ write_code = True
33
+
34
+ if sys.argv[2] == "api":
35
+ entities = self.__import_from_api()
36
+ elif sys.argv[2] == "datastore":
37
+ entities = self.__import_from_datastore()
38
+ else:
39
+ self.usage()
40
+
41
+ self.memory.remember_entities(entities)
42
+
43
+ word_entities = "entities"
44
+ if len(entities) == 1:
45
+ word_entities = "entity"
46
+
47
+ self.conversation.type("\nSummary\n")
48
+ self.conversation.type(f" {len(entities)} {word_entities} imported\n")
49
+ self.conversation.newline()
50
+
51
+ if write_code:
52
+ Rewrite(self.configuration).execute()
53
+ self.conversation.newline()
54
+
55
+ return True
56
+
57
+ def __import_from_api(self):
58
+ self.conversation.display_project(self.configuration.project.name)
59
+
60
+ self.conversation.type("Connected to API...\n")
61
+ response = Cli(self.configuration).import_()
62
+ self.conversation.type("Building schema...\n")
63
+
64
+ entities = []
65
+ for entity in response["project"]["entities"]:
66
+ self.conversation.type(f" {entity['name']}\n", delay=0.002)
67
+
68
+ return response["project"]["entities"]
69
+
70
+ def __import_from_datastore(self):
71
+ self.conversation.display_project(self.configuration.project.name)
72
+
73
+ db = create_engine(self.configuration.project.datastore.uri)
74
+ session = sessionmaker(autocommit=False, autoflush=False, bind=db)()
75
+
76
+ table_exceptions = TableExceptions().universal()
77
+ if self.configuration.project.datastore.type == "mysql":
78
+ table_exceptions = TableExceptions().mysql()
79
+
80
+ self.conversation.type("Connected to datastore...\n")
81
+ self.conversation.type("Building schema...\n")
82
+
83
+ tables = session.execute("show tables").all()
84
+
85
+ entities = []
86
+ for table in tables:
87
+ if table[0] not in table_exceptions:
88
+ self.conversation.type(f" {table[0]}\n", delay=0.002)
89
+
90
+ create_statement = session.execute(
91
+ f"show create table {table[0]}"
92
+ ).one()
93
+
94
+ entities.append(
95
+ {"definition": str(create_statement[1]), "name": str(table[0])}
96
+ )
97
+
98
+ return entities
99
+
100
+ def usage(self):
101
+ self.conversation.display_project(self.configuration.project.name)
102
+ self.conversation.type(
103
+ f"usage: {self.configuration.command} import [api | datastore] {{.. dev}}"
104
+ + "\n api = the project stored in your API key on GibsonAI.com\n"
105
+ + f" datastore = {self.configuration.project.datastore.uri}\n"
106
+ + " {.. dev} have Dev Mode write all the code\n"
107
+ )
108
+ self.conversation.newline()
109
+ exit(1)
command/List.py ADDED
@@ -0,0 +1,61 @@
1
+ import sys
2
+
3
+ from api.Cli import Cli
4
+
5
+ from .BaseCommand import BaseCommand
6
+
7
+
8
+ class List(BaseCommand):
9
+ def execute(self):
10
+ if len(sys.argv) != 3:
11
+ self.usage()
12
+
13
+ self.conversation.display_project(self.configuration.project.name)
14
+
15
+ entities = {"last": [], "stored": []}
16
+
17
+ last = self.memory.recall_last()
18
+ if last is not None:
19
+ for entity in last["entities"]:
20
+ entities["last"].append(entity["name"])
21
+
22
+ stored = self.memory.recall_entities()
23
+ if stored is not None:
24
+ for entity in stored:
25
+ entities["stored"].append(entity["name"])
26
+
27
+ if len(entities["last"]) == 0 and len(entities["stored"]) == 0:
28
+ self.conversation.nothing_to_list(sys.argv[2])
29
+ self.conversation.newline()
30
+ else:
31
+ self.conversation.type(" Name".ljust(60), delay=0.0001)
32
+ self.conversation.type("Memory", delay=0.002)
33
+ self.conversation.newline()
34
+ self.conversation.type(" ----".ljust(60), delay=0.0001)
35
+ self.conversation.type("------", delay=0.002)
36
+ self.conversation.newline()
37
+
38
+ entities["last"].sort()
39
+ entities["stored"].sort()
40
+
41
+ if len(entities["stored"]) > 0:
42
+ for entity in entities["stored"]:
43
+ self.conversation.type(f" {entity}".ljust(60), delay=0.0001)
44
+ self.conversation.type("[stored]", delay=0.002)
45
+ self.conversation.newline()
46
+
47
+ self.conversation.newline()
48
+
49
+ if len(entities["last"]) > 0:
50
+ for entity in entities["last"]:
51
+ self.conversation.type(f" {entity}".ljust(60), delay=0.0001)
52
+ self.conversation.type("[last]", delay=0.002)
53
+ self.conversation.newline()
54
+
55
+ self.conversation.newline()
56
+
57
+ def usage(self):
58
+ self.conversation.display_project(self.configuration.project.name)
59
+ self.conversation.type(f"usage: {self.configuration.command} list entities\n")
60
+ self.conversation.newline()
61
+ exit(1)
command/Merge.py ADDED
@@ -0,0 +1,35 @@
1
+ import sys
2
+
3
+ from api.Cli import Cli
4
+
5
+ from .BaseCommand import BaseCommand
6
+
7
+
8
+ class Merge(BaseCommand):
9
+ def execute(self):
10
+ self.conversation.display_project(self.configuration.project.name)
11
+
12
+ if self.memory.last is None or "entities" not in self.memory.last:
13
+ self.conversation.type("No bueno. There is nothing to merge.\n\n")
14
+ exit(1)
15
+
16
+ if self.memory.entities is None:
17
+ self.memory.entities = []
18
+
19
+ entity_map = {}
20
+ for i in range(len(self.memory.entities)):
21
+ entity_map[self.memory.entities[i]["name"]] = i
22
+
23
+ for entity in self.memory.last["entities"]:
24
+ if entity["name"] not in entity_map:
25
+ self.memory.entities.append(entity)
26
+ else:
27
+ self.memory.entities[entity_map[entity["name"]]] = entity
28
+
29
+ self.conversation.type(f"[Merged] {entity['name']}\n")
30
+
31
+ self.memory.remember_entities(self.memory.entities)
32
+ self.memory.forget_last()
33
+ self.memory.last = None
34
+
35
+ self.conversation.newline()
command/Model.py ADDED
@@ -0,0 +1,42 @@
1
+ import sys
2
+
3
+ from api.Cli import Cli
4
+ from dev.Dev import Dev
5
+ from core.TimeKeeper import TimeKeeper
6
+
7
+ from .BaseCommand import BaseCommand
8
+
9
+
10
+ class Model(BaseCommand):
11
+ def execute(self):
12
+ if len(sys.argv) != 3:
13
+ self.usage()
14
+
15
+ entity = self.memory.recall_stored_entity(sys.argv[2])
16
+ if entity is None:
17
+ self.conversation.not_sure_no_entity(
18
+ self.configuration.project.name, sys.argv[2]
19
+ )
20
+ exit(1)
21
+
22
+ time_keeper = TimeKeeper()
23
+
24
+ cli = Cli(self.configuration)
25
+ response = cli.code_models([entity["name"]])
26
+
27
+ Dev(self.configuration).model(
28
+ response["code"][0]["entity"]["name"], response["code"][0]["definition"]
29
+ )
30
+
31
+ print(response["code"][0]["definition"])
32
+ time_keeper.display()
33
+
34
+ def usage(self):
35
+ self.conversation.display_project(self.configuration.project.name)
36
+ self.conversation.type(
37
+ f"usage: {self.configuration.command} model [entity name]\n"
38
+ + " where [entity name] is one of the entities that exists "
39
+ + "in this project\n"
40
+ )
41
+ self.conversation.newline()
42
+ exit(1)
command/Models.py ADDED
@@ -0,0 +1,31 @@
1
+ from api.Cli import Cli
2
+ from dev.Dev import Dev
3
+ from core.TimeKeeper import TimeKeeper
4
+
5
+ from .BaseCommand import BaseCommand
6
+
7
+
8
+ class Models(BaseCommand):
9
+ def execute(self):
10
+ entities = []
11
+ if self.memory.entities is not None:
12
+ for entity in self.memory.entities:
13
+ entities.append(entity["name"])
14
+
15
+ if len(entities) == 0:
16
+ self.conversation.cant_no_entities(self.configuration.project.name)
17
+ exit(1)
18
+
19
+ time_keeper = TimeKeeper()
20
+
21
+ cli = Cli(self.configuration)
22
+ response = cli.code_models(entities)
23
+
24
+ for entry in response["code"]:
25
+ Dev(self.configuration).model(entry["entity"]["name"], entry["definition"])
26
+
27
+ if self.conversation.muted() is False:
28
+ print(entry["definition"])
29
+
30
+ if self.conversation.muted() is False:
31
+ time_keeper.display()
command/Modify.py ADDED
@@ -0,0 +1,43 @@
1
+ import sys
2
+
3
+ from api.Cli import Cli
4
+
5
+ from .BaseCommand import BaseCommand
6
+
7
+
8
+ class Modify(BaseCommand):
9
+ def execute(self):
10
+ if len(sys.argv) < 4:
11
+ self.usage()
12
+
13
+ entity = self.memory.recall_entity(sys.argv[2])
14
+ if entity is None:
15
+ self.conversation.not_sure_no_entity(
16
+ self.configuration.project.name, sys.argv[2]
17
+ )
18
+ exit(1)
19
+
20
+ cli = Cli(self.configuration)
21
+
22
+ response = cli.modeler_entity_modify(
23
+ self.configuration.project.modeler.version,
24
+ self.configuration.project.description,
25
+ entity,
26
+ " ".join(sys.argv[3:]),
27
+ )
28
+
29
+ self.memory.remember_last(response)
30
+
31
+ print(response["entities"][0]["definition"])
32
+
33
+ def usage(self):
34
+ self.conversation.display_project(self.configuration.project.name)
35
+ self.conversation.type(
36
+ f"usage: {self.configuration.command} "
37
+ + "modify [entity name] [instructions]\n"
38
+ + " where [entity name] is one of the entities that exists in "
39
+ + "this project\n"
40
+ + " and [instructions] is natural language describing the changes\n"
41
+ )
42
+ self.conversation.newline()
43
+ exit(1)
command/Module.py ADDED
@@ -0,0 +1,42 @@
1
+ import re
2
+ import sys
3
+
4
+ from api.Cli import Cli
5
+
6
+ from .BaseCommand import BaseCommand
7
+
8
+
9
+ class Module(BaseCommand):
10
+ def execute(self):
11
+ if len(sys.argv) != 3:
12
+ self.usage()
13
+
14
+ if not re.search("^[a-z0-9]+$", sys.argv[2]):
15
+ self.conversation.display_project(self.configuration.project.name)
16
+ self.conversation.type("[module name] should only contain ^[a-z0-9]+$.\n\n")
17
+ return True
18
+
19
+ cli = Cli(self.configuration)
20
+
21
+ response = cli.modeler_module(
22
+ self.configuration.project.modeler.version,
23
+ self.configuration.project.description,
24
+ sys.argv[2],
25
+ )
26
+
27
+ self.memory.remember_last(response)
28
+
29
+ for entity in response["entities"]:
30
+ print(entity["definition"])
31
+ self.conversation.newline()
32
+
33
+ def usage(self):
34
+ self.conversation.display_project(self.configuration.project.name)
35
+ self.conversation.type(
36
+ f"usage: {self.configuration.command} module [module name]\n"
37
+ + " where [module name] is the name of the module I should create for "
38
+ + "this project\n"
39
+ + " [module name] ~ ^[a-z0-9]+$\n"
40
+ )
41
+ self.conversation.newline()
42
+ exit(1)
command/New.py ADDED
@@ -0,0 +1,38 @@
1
+ import os
2
+ import re
3
+ import sys
4
+
5
+ from api.Cli import Cli
6
+
7
+ from .BaseCommand import BaseCommand
8
+
9
+
10
+ class New(BaseCommand):
11
+ def execute(self):
12
+ if len(sys.argv) != 3:
13
+ self.usage()
14
+
15
+ if sys.argv[2] != "project":
16
+ self.usage()
17
+
18
+ self.conversation.new_project(self.configuration)
19
+ project_name = self.conversation.prompt_project()
20
+ if project_name in self.configuration.settings:
21
+ self.conversation.project_already_exists(project_name)
22
+ exit(1)
23
+
24
+ project_description = self.conversation.prompt_description(project_name)
25
+
26
+ self.configuration.set_project_env(project_name)
27
+ self.configuration.append_project_to_conf(project_name, project_description)
28
+
29
+ self.conversation.configure_new_project(self.configuration)
30
+
31
+ def usage(self):
32
+ self.conversation.display_project(self.configuration.project.name)
33
+ self.conversation.type(
34
+ f"usage: {self.configuration.command} new [thing]\n"
35
+ + ' where [thing] can only be "project", for now\n'
36
+ )
37
+ self.conversation.newline()
38
+ exit(1)