Skip to content

Commit

Permalink
Adding New function to diaplay suse-uptime-tracker version
Browse files Browse the repository at this point in the history
  • Loading branch information
cjainsuse committed Sep 24, 2024
1 parent 821ddd7 commit d6af6e7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
6 changes: 1 addition & 5 deletions build/packaging/suseconnect-ng.changes
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
------------------------------------------------------------------
Wed Aug 28 20:31:47 UTC 2024 - Charu Jain <[email protected]>

- Integrating uptime-tracker

-------------------------------------------------------------------
Fri Sep 13 15:56:05 UTC 2024 - Miquel Sabate Sola <[email protected]>

- IN PROGRESS: 1.13
- Integrating uptime-tracker

-------------------------------------------------------------------
Fri Sep 13 14:11:22 UTC 2024 - Miquel Sabate Sola <[email protected]>
Expand Down
36 changes: 19 additions & 17 deletions cmd/suse-uptime-tracker/uptime_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const (
daysBeforePurge = 90 // purge all the records after this many days
)

// getShortenedVersion returns the short program version
func getShortenedVersion() string {
return strings.Split(strings.TrimSpace(version), "~")[0]
}
Expand All @@ -39,6 +38,24 @@ func exitOnError(err error) {
os.Exit(1)
}

func displayUptimeVersion() {
var (
version bool
)

flag.Usage = func() {
fmt.Print(uptimeTrackerUsageText)
}

flag.BoolVar(&version, "version", false, "")

flag.Parse()
if version {
fmt.Println(getShortenedVersion())
os.Exit(0)
}
}

func readUptimeLogFile(uptimeLogsFilePath string) (map[string]string, error) {
uptimeLogsFile, err := os.Open(uptimeLogsFilePath)
if err != nil {
Expand Down Expand Up @@ -124,22 +141,7 @@ func writeUptimeLogsFile(uptimeLogsFilePath string, uptimeLogs map[string]string
}

func main() {
var (
version bool
)

flag.Usage = func() {
fmt.Print(uptimeTrackerUsageText)
}

flag.BoolVar(&version, "version", false, "")

flag.Parse()
if version {
fmt.Println(getShortenedVersion())
os.Exit(0)
}

displayUptimeVersion()
uptimeLogs, err := readUptimeLogFile(uptimeCheckLogsFilePath)
exitOnError(err)
uptimeLogs, err = purgeOldUptimeLog(uptimeLogs)
Expand Down

0 comments on commit d6af6e7

Please sign in to comment.