(context: Context)
| 69 | |
| 70 | |
| 71 | def get_command_collection(context: Context): |
| 72 | # default commands |
| 73 | commands = click.CommandCollection(sources=[common, dev]) |
| 74 | |
| 75 | # treat gsctl as an utility script, providing helper functions or utilities |
| 76 | # e.g. initialize and manage cluster, install the dependencies required to |
| 77 | # build graphscope locally. |
| 78 | if context is None: |
| 79 | if len(sys.argv) == 1: |
| 80 | info(logo, fg="green", bold=True) |
| 81 | info(usage_message, fg="red") |
| 82 | return commands |
| 83 | |
| 84 | if context.is_expired(): |
| 85 | try: |
| 86 | # connect to coordinator and reset the timestamp |
| 87 | response = connect_coordinator(context.coordinator_endpoint) |
| 88 | flex = { |
| 89 | "engine": response.engine, |
| 90 | "storage": response.storage, |
| 91 | "frontend": response.frontend, |
| 92 | } |
| 93 | except Exception as e: |
| 94 | err( |
| 95 | "Failed to connect to coordinator at {0}: {1}".format( |
| 96 | context.coordinator_endpoint, str(e) |
| 97 | ) |
| 98 | ) |
| 99 | info( |
| 100 | "Please check the availability of the service, fall back to the default commands." |
| 101 | ) |
| 102 | return commands |
| 103 | else: |
| 104 | # check consistency |
| 105 | if flex != context.flex: |
| 106 | raise RuntimeError( |
| 107 | f"Instance changed: {context.flex} -> {flex}, please close and reconnect to the coordinator" |
| 108 | ) |
| 109 | context.reset_timestamp() |
| 110 | config = load_gs_config() |
| 111 | config.update_and_write(context) |
| 112 | |
| 113 | if is_interactive_mode(context.flex): |
| 114 | if context.context == "global": |
| 115 | if len(sys.argv) < 2 or sys.argv[1] != "use": |
| 116 | info(interactive_usage_message, fg="green") |
| 117 | commands = click.CommandCollection(sources=[common, interactive]) |
| 118 | else: |
| 119 | if len(sys.argv) < 2 or sys.argv[1] != "use": |
| 120 | info( |
| 121 | f"Using GRAPH {context.graph_name}(id={context.context}).", |
| 122 | fg="green", |
| 123 | bold=True, |
| 124 | ) |
| 125 | info( |
| 126 | "Run `gsctl use GLOBAL` to switch back to GLOBAL context.\n", |
| 127 | fg="green", |
| 128 | ) |
no test coverage detected