2022-11-15 04:26:56 +01:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/ddworken/hishtory/client/data"
|
|
|
|
"github.com/ddworken/hishtory/client/hctx"
|
|
|
|
"github.com/ddworken/hishtory/client/lib"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var verbose *bool
|
|
|
|
|
|
|
|
var statusCmd = &cobra.Command{
|
|
|
|
Use: "status",
|
2022-11-15 05:18:22 +01:00
|
|
|
Short: "View status info including the secret key which is needed to sync shell history from another machine",
|
2022-11-15 04:26:56 +01:00
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
ctx := hctx.MakeContext()
|
|
|
|
config := hctx.GetConf(ctx)
|
|
|
|
fmt.Printf("hiSHtory: v0.%s\nEnabled: %v\n", lib.Version, config.IsEnabled)
|
|
|
|
fmt.Printf("Secret Key: %s\n", config.UserSecret)
|
|
|
|
if *verbose {
|
|
|
|
fmt.Printf("User ID: %s\n", data.UserId(config.UserSecret))
|
|
|
|
fmt.Printf("Device ID: %s\n", config.DeviceId)
|
2023-09-08 03:10:17 +02:00
|
|
|
printOnlineStatus(config)
|
2022-11-15 04:26:56 +01:00
|
|
|
}
|
|
|
|
fmt.Printf("Commit Hash: %s\n", lib.GitCommit)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2023-09-23 21:40:57 +02:00
|
|
|
func printOnlineStatus(config *hctx.ClientConfig) {
|
2023-09-08 03:10:17 +02:00
|
|
|
if config.IsOffline {
|
|
|
|
fmt.Println("Sync Mode: Disabled")
|
|
|
|
} else {
|
|
|
|
fmt.Println("Sync Mode: Enabled")
|
2024-02-11 22:54:00 +01:00
|
|
|
if lib.GetServerHostname() != lib.DefaultServerHostname {
|
|
|
|
fmt.Println("Sync Server: " + lib.GetServerHostname())
|
|
|
|
}
|
2023-09-24 04:57:41 +02:00
|
|
|
if config.HaveMissedUploads || len(config.PendingDeletionRequests) > 0 {
|
2023-09-08 03:10:17 +02:00
|
|
|
fmt.Println("Sync Status: Unsynced (device is offline?)")
|
2023-11-25 01:09:16 +01:00
|
|
|
fmt.Printf(" HaveMissedUploads=%v MissedUploadTimestamp=%v len(PendingDeletionRequests)=%v\n", config.HaveMissedUploads, config.MissedUploadTimestamp, len(config.PendingDeletionRequests))
|
2023-09-08 03:10:17 +02:00
|
|
|
} else {
|
|
|
|
fmt.Println("Sync Status: Synced")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-15 04:26:56 +01:00
|
|
|
func init() {
|
|
|
|
rootCmd.AddCommand(statusCmd)
|
|
|
|
verbose = statusCmd.Flags().BoolP("verbose", "v", false, "Display verbose hiSHtory information")
|
|
|
|
}
|