Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Go Build and Test

on: [push]

jobs:
build:

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.20'

- name: Build
run: go build -v ./...

- name: Test
run: go test -v ./...
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@
go.work

.vscode/
config.toml
config.toml

# build
pb
20 changes: 0 additions & 20 deletions cli_style.go

This file was deleted.

38 changes: 0 additions & 38 deletions client.go

This file was deleted.

55 changes: 55 additions & 0 deletions cmd/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (c) 2023 Cloudnatively Services Pvt Ltd
//
// This file is part of MinIO Object Storage stack
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

package cmd

import (
"io"
"net/http"
"net/url"
"pb/pkg/config"
"time"
)

type HttpClient struct {
client http.Client
profile *config.Profile
}

func DefaultClient() HttpClient {
return HttpClient{
client: http.Client{
Timeout: 60 * time.Second,
},
profile: &DefaultProfile,
}
}

func (client *HttpClient) baseApiUrl(path string) (x string) {
x, _ = url.JoinPath(client.profile.Url, "api/v1/", path)
return
}

func (client *HttpClient) NewRequest(method string, path string, body io.Reader) (req *http.Request, err error) {
req, err = http.NewRequest(method, client.baseApiUrl(path), body)
if err != nil {
return
}
req.SetBasicAuth(client.profile.Username, client.profile.Password)
req.Header.Add("Content-Type", "application/json")
return
}
47 changes: 47 additions & 0 deletions cmd/pre.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (c) 2023 Cloudnatively Services Pvt Ltd
//
// This file is part of MinIO Object Storage stack
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

package cmd

import (
"errors"
"os"
"pb/pkg/config"

"github.com/spf13/cobra"
)

var DefaultProfile config.Profile

// Check if a profile exists.
// This is required by mostly all commands except profile
func PreRunDefaultProfile(cmd *cobra.Command, args []string) error {
conf, err := config.ReadConfigFromFile()
if err != nil {
if os.IsNotExist(err) {
return errors.New("No config found to run this command. Add a profile using pb profile command")
} else {
return err
}
}
if conf.Profiles == nil || conf.Default_profile == "" {
return errors.New("no profile is configured to run this command. please create one using profile command")
}

DefaultProfile = conf.Profiles[conf.Default_profile]
return nil
}
23 changes: 20 additions & 3 deletions profile_cmds.go → cmd/profile.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
package main
// Copyright (c) 2023 Cloudnatively Services Pvt Ltd
//
// This file is part of MinIO Object Storage stack
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

package cmd

import (
"cli/config"
"cli/model"
"errors"
"fmt"
"net/url"
"os"
"pb/pkg/config"
"pb/pkg/model"

"github.com/charmbracelet/bubbles/table"
tea "github.com/charmbracelet/bubbletea"
Expand Down
43 changes: 43 additions & 0 deletions cmd/query.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) 2023 Cloudnatively Services Pvt Ltd
//
// This file is part of MinIO Object Storage stack
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

package cmd

import (
"fmt"
"os"
"pb/pkg/model"

tea "github.com/charmbracelet/bubbletea"
"github.com/spf13/cobra"
)

var QueryProfileCmd = &cobra.Command{
Use: "query name",
Short: "Open Query TUI",
Args: cobra.ExactArgs(1),
PreRunE: PreRunDefaultProfile,
RunE: func(cmd *cobra.Command, args []string) error {
stream := args[0]
p := tea.NewProgram(model.NewQueryModel(DefaultProfile, stream), tea.WithAltScreen())
if _, err := p.Run(); err != nil {
fmt.Printf("Alas, there's been an error: %v", err)
os.Exit(1)
}
return nil
},
}
19 changes: 18 additions & 1 deletion stream_cmds.go → cmd/stream.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
package main
// Copyright (c) 2023 Cloudnatively Services Pvt Ltd
//
// This file is part of MinIO Object Storage stack
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

package cmd

import (
"encoding/json"
Expand Down
37 changes: 37 additions & 0 deletions cmd/style.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) 2023 Cloudnatively Services Pvt Ltd
//
// This file is part of MinIO Object Storage stack
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

package cmd

import (
"github.com/charmbracelet/bubbles/table"
"github.com/charmbracelet/lipgloss"
)

// styling for cli outputs
var (
selectedStyle = lipgloss.NewStyle().
Foreground(lipgloss.AdaptiveColor{Light: "4", Dark: "11"}).Bold(true)
styleBold = lipgloss.NewStyle().Bold(true)
)

func listingTableStyle() table.Styles {
s := table.DefaultStyles()
s.Header = s.Header.Border(lipgloss.NormalBorder(), false, false, true, false)
s.Selected = selectedStyle
return s
}
19 changes: 18 additions & 1 deletion user_cmds.go → cmd/user.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
package main
// Copyright (c) 2023 Cloudnatively Services Pvt Ltd
//
// This file is part of MinIO Object Storage stack
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

package cmd

import (
"encoding/json"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module cli
module pb

go 1.20

Expand Down
Loading