kloudlite / kl

Kloudlite CLI Client
GNU Affero General Public License v3.0
5 stars 1 forks source link

connect cmd implemented #164

Closed nxtcoder36 closed 2 weeks ago

nxtcoder36 commented 2 weeks ago

Summary by Sourcery

Introduce a 'connect' command for managing WireGuard connections and refactor container restart logic. Enhance K3s server readiness checks and update the Taskfile to monitor additional file types.

New Features:

Enhancements:

Build:

sourcery-ai[bot] commented 2 weeks ago

Reviewer's Guide by Sourcery

This pull request implements the 'connect' command and makes several improvements to the existing codebase. The changes focus on enhancing the restart functionality, improving the status command, and adding new features to the K3s client.

Sequence diagram for the restartBoxContainer process

sequenceDiagram
    participant User
    participant Client
    participant CLI
    participant Container

    User->>Client: Initiate restartBoxContainer
    Client->>CLI: ContainerList with filters
    alt Containers exist
        Client->>User: Confirm restart
        User->>Client: Confirm (Y/n)
        alt User cancels
            Client->>User: Return UserCanceled error
        end
    end
    loop For each container
        Client->>Container: ContainerStop
        Container-->>Client: Stop response
        Client->>Container: ContainerRemove
        Container-->>Client: Remove response
    end
    Client->>CLI: Start
    CLI-->>Client: Start response
    Client-->>User: Return success or error

Sequence diagram for startWg process

sequenceDiagram
    participant User
    participant ConnectCommand
    participant K3sClient

    User->>ConnectCommand: Execute startWg
    ConnectCommand->>K3sClient: NewClient
    alt Error in NewClient
        ConnectCommand-->>User: Return error
    end
    ConnectCommand->>ConnectCommand: ExecNoOutput("wg-quick down kl-workspace-wg")
    alt Error in ExecNoOutput
        ConnectCommand-->>User: Return error
    end
    ConnectCommand->>ConnectCommand: ExecNoOutput("wg-quick up kl-workspace-wg")
    alt Error in ExecNoOutput
        ConnectCommand-->>User: Return error
    end
    ConnectCommand->>K3sClient: RestartWgProxyContainer
    K3sClient-->>ConnectCommand: Return success or error
    ConnectCommand-->>User: Return success or error

Class diagram for Exec function changes

classDiagram
    class functions {
        +Exec(cmdString string, env map[string]string) ([]byte, error)
        +ExecNoOutput(cmdString string) error
    }

File-Level Changes

Change Details Files
Implemented 'connect' command
  • Added new 'connect' command to the CLI
  • Implemented startWg() function to handle WireGuard connections
  • Added error handling for WireGuard operations
cmd/connect/connect.go
clis/kl/loadsubs.go
Enhanced restart functionality
  • Implemented restartBoxContainer() function
  • Added user confirmation before restarting workspace
  • Improved container stopping and removal process
cmd/box/boxpkg/restart.go
Improved K3s client functionality
  • Added CheckK3sServerIsReady() method
  • Renamed ensureK3sServerIsReady() to EnsureK3sServerIsReady()
  • Updated RestartWgProxyContainer() to ensure K3s server is ready after restart
pkg/k3s/impl.go
pkg/k3s/main.go
Updated status command
  • Commented out existing device status check
  • Prepared new implementation using K3s client (currently commented out)
cmd/status/status.go
Added new utility function
  • Implemented ExecNoOutput() function for command execution without output
pkg/functions/exec.go
Updated build configuration
  • Modified nodemon watch extensions in Taskfile.yml
Taskfile.yml
Adjusted command availability
  • Limited 'connect' command to inside box environment
  • Limited 'info' command to outside box environment
clis/kl/loadsubs.go
cmd/box/klbox.go

Tips and commands #### Interacting with Sourcery - **Trigger a new review:** Comment `@sourcery-ai review` on the pull request. - **Continue discussions:** Reply directly to Sourcery's review comments. - **Generate a GitHub issue from a review comment:** Ask Sourcery to create an issue from a review comment by replying to it. #### Customizing Your Experience Access your [dashboard](https://app.sourcery.ai) to: - Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others. - Change the review language. - Add, remove or edit custom review instructions. - Adjust other review settings. #### Getting Help - [Contact our support team](mailto:support@sourcery.ai) for questions or feedback. - Visit our [documentation](https://docs.sourcery.ai) for detailed guides and information. - Keep in touch with the Sourcery team by following us on [X/Twitter](https://x.com/SourceryAI), [LinkedIn](https://www.linkedin.com/company/sourcery-ai/) or [GitHub](https://github.com/sourcery-ai).