Skip to content

Commit

Permalink
streamline pre runs
Browse files Browse the repository at this point in the history
  • Loading branch information
AdheipSingh committed Nov 10, 2024
1 parent 5149d83 commit 2e2d91d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 14 deletions.
1 change: 1 addition & 0 deletions cmd/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
//
// 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 (
Expand Down
2 changes: 1 addition & 1 deletion cmd/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ var ListStreamCmd = &cobra.Command{
Use: "list",
Example: " pb stream list",
Short: "List all streams",
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {
// Capture start time
startTime := time.Now()
cmd.Annotations = make(map[string]string)
Expand Down
1 change: 0 additions & 1 deletion cmd/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ var AddUserCmd = func() *cobra.Command {
return addUser
}()

// Similar changes for RemoveUserCmd
var RemoveUserCmd = &cobra.Command{
Use: "remove user-name",
Aliases: []string{"rm"},
Expand Down
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var VersionCmd = &cobra.Command{
Short: "Print version",
Long: "Print version and commit information",
Example: " pb version",
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
if cmd.Annotations == nil {
cmd.Annotations = make(map[string]string)
}
Expand Down
39 changes: 28 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"os"
"pb/cmd"
pb "pb/cmd"
"pb/pkg/analytics"
"pb/pkg/config"

Expand Down Expand Up @@ -48,12 +49,13 @@ func defaultInitialProfile() config.Profile {

// Root command
var cli = &cobra.Command{
Use: "pb",
Short: "\nParseable command line interface",
Long: "\npb is the command line interface for Parseable",
Use: "pb",
Short: "\nParseable command line interface",
Long: "\npb is the command line interface for Parseable",
PersistentPreRunE: analytics.CheckAndCreateUUID,
RunE: func(command *cobra.Command, _ []string) error {
if p, _ := command.Flags().GetBool(versionFlag); p {
cmd.PrintVersion(Version, Commit)
pb.PrintVersion(Version, Commit)
return nil
}
return errors.New("no command or flag supplied")
Expand All @@ -64,9 +66,10 @@ var cli = &cobra.Command{
}

var profile = &cobra.Command{
Use: "profile",
Short: "Manage different Parseable targets",
Long: "\nuse profile command to configure different Parseable instances. Each profile takes a URL and credentials.",
Use: "profile",
Short: "Manage different Parseable targets",
Long: "\nuse profile command to configure different Parseable instances. Each profile takes a URL and credentials.",
PersistentPreRunE: combinedPreRun,
PersistentPostRun: func(cmd *cobra.Command, args []string) {
analytics.PostRunAnalytics(cmd, args)
},
Expand All @@ -76,7 +79,7 @@ var user = &cobra.Command{
Use: "user",
Short: "Manage users",
Long: "\nuser command is used to manage users.",
PersistentPreRunE: cmd.PreRunDefaultProfile,
PersistentPreRunE: combinedPreRun,
PersistentPostRun: func(cmd *cobra.Command, args []string) {
analytics.PostRunAnalytics(cmd, args)
},
Expand All @@ -86,7 +89,7 @@ var role = &cobra.Command{
Use: "role",
Short: "Manage roles",
Long: "\nrole command is used to manage roles.",
PersistentPreRunE: cmd.PreRunDefaultProfile,
PersistentPreRunE: combinedPreRun,
PersistentPostRun: func(cmd *cobra.Command, args []string) {
analytics.PostRunAnalytics(cmd, args)
},
Expand All @@ -96,7 +99,7 @@ var stream = &cobra.Command{
Use: "stream",
Short: "Manage streams",
Long: "\nstream command is used to manage streams.",
PersistentPreRunE: cmd.PreRunDefaultProfile,
PersistentPreRunE: combinedPreRun,
PersistentPostRun: func(cmd *cobra.Command, args []string) {
analytics.PostRunAnalytics(cmd, args)
},
Expand All @@ -106,7 +109,7 @@ var query = &cobra.Command{
Use: "query",
Short: "Run SQL query on a log stream",
Long: "\nRun SQL query on a log stream. Default output format is json. Use -i flag to open interactive table view.",
PersistentPreRunE: cmd.PreRunDefaultProfile,
PersistentPreRunE: combinedPreRun,
PersistentPostRun: func(cmd *cobra.Command, args []string) {
analytics.PostRunAnalytics(cmd, args)
},
Expand Down Expand Up @@ -194,3 +197,17 @@ func main() {
os.Exit(1)
}
}

// Wrapper to combine existing pre-run logic and UUID check
func combinedPreRun(cmd *cobra.Command, args []string) error {
err := pb.PreRunDefaultProfile(cmd, args)
if err != nil {
return fmt.Errorf("error initialising default profile: %w", err)
}

Check failure on line 206 in main.go

View workflow job for this annotation

GitHub Actions / Build and Test the Go code

`initialising` is a misspelling of `initializing` (misspell)

if err := analytics.CheckAndCreateUUID(cmd, args); err != nil {
return fmt.Errorf("error while creating UUID: %v", err)
}

return nil
}

0 comments on commit 2e2d91d

Please sign in to comment.