From 8d922ccd819db47ddac611743b0a304f48482de2 Mon Sep 17 00:00:00 2001 From: Felicitas Pojtinger Date: Wed, 15 Dec 2021 21:11:18 +0100 Subject: [PATCH] refactor: Use string-backed enums consistently --- cmd/stbak/cmd/drive_root.go | 5 +++-- cmd/stbak/cmd/inventory_root.go | 5 +++-- cmd/stbak/cmd/operation_root.go | 5 +++-- cmd/stbak/cmd/recovery_root.go | 5 +++-- internal/logging/csv.go | 16 +--------------- pkg/config/constants.go | 10 +++++----- pkg/config/events.go | 2 +- 7 files changed, 19 insertions(+), 29 deletions(-) diff --git a/cmd/stbak/cmd/drive_root.go b/cmd/stbak/cmd/drive_root.go index 6de66a8..cf52005 100644 --- a/cmd/stbak/cmd/drive_root.go +++ b/cmd/stbak/cmd/drive_root.go @@ -6,8 +6,9 @@ import ( ) var driveCmd = &cobra.Command{ - Use: "drive", - Short: "Manage tape drives", + Use: "drive", + Aliases: []string{"dri", "d"}, + Short: "Manage tape drives", } func init() { diff --git a/cmd/stbak/cmd/inventory_root.go b/cmd/stbak/cmd/inventory_root.go index a051e68..d6b3922 100644 --- a/cmd/stbak/cmd/inventory_root.go +++ b/cmd/stbak/cmd/inventory_root.go @@ -6,8 +6,9 @@ import ( ) var inventoryCmd = &cobra.Command{ - Use: "inventory", - Short: "Get contents and metadata of tape or tar file from the index", + Use: "inventory", + Aliases: []string{"inv", "i"}, + Short: "Get contents and metadata of tape or tar file from the index", } func init() { diff --git a/cmd/stbak/cmd/operation_root.go b/cmd/stbak/cmd/operation_root.go index 83e8764..0ffab1f 100644 --- a/cmd/stbak/cmd/operation_root.go +++ b/cmd/stbak/cmd/operation_root.go @@ -6,8 +6,9 @@ import ( ) var operationCmd = &cobra.Command{ - Use: "operation", - Short: "Perform operations on tape or tar file and the index", + Use: "operation", + Aliases: []string{"ope", "o", "op"}, + Short: "Perform operations on tape or tar file and the index", } func init() { diff --git a/cmd/stbak/cmd/recovery_root.go b/cmd/stbak/cmd/recovery_root.go index 48296c1..70d0e28 100644 --- a/cmd/stbak/cmd/recovery_root.go +++ b/cmd/stbak/cmd/recovery_root.go @@ -6,8 +6,9 @@ import ( ) var recoveryCmd = &cobra.Command{ - Use: "recovery", - Short: "Recover tapes or tar files", + Use: "recovery", + Aliases: []string{"rec", "r"}, + Short: "Recover tapes or tar files", } func init() { diff --git a/internal/logging/csv.go b/internal/logging/csv.go index 463be57..6051b89 100644 --- a/internal/logging/csv.go +++ b/internal/logging/csv.go @@ -24,21 +24,7 @@ func headerToCSV(hdr *models.Header) []string { } func headerEventToCSV(event *config.HeaderEvent) []string { - headerType := "unknown" - switch event.Type { - case config.HeaderEventTypeArchive: - headerType = "archive" - case config.HeaderEventTypeDelete: - headerType = "delete" - case config.HeaderEventTypeMove: - headerType = "move" - case config.HeaderEventTypeRestore: - headerType = "restore" - case config.HeaderEventTypeUpdate: - headerType = "update" - } - - return append([]string{headerType, fmt.Sprintf("%v", event.Indexed)}, headerToCSV(event.Header)...) + return append([]string{event.Type, fmt.Sprintf("%v", event.Indexed)}, headerToCSV(event.Header)...) } type Logger struct { diff --git a/pkg/config/constants.go b/pkg/config/constants.go index 9cade01..a2cb69c 100644 --- a/pkg/config/constants.go +++ b/pkg/config/constants.go @@ -21,11 +21,11 @@ const ( CompressionLevelBalanced = "balanced" CompressionLevelSmallest = "smallest" - HeaderEventTypeArchive = 0 - HeaderEventTypeDelete = 1 - HeaderEventTypeMove = 2 - HeaderEventTypeRestore = 3 - HeaderEventTypeUpdate = 4 + HeaderEventTypeArchive = "archive" + HeaderEventTypeDelete = "delete" + HeaderEventTypeMove = "move" + HeaderEventTypeRestore = "restore" + HeaderEventTypeUpdate = "update" ) var ( diff --git a/pkg/config/events.go b/pkg/config/events.go index de7a2af..0bfe146 100644 --- a/pkg/config/events.go +++ b/pkg/config/events.go @@ -3,7 +3,7 @@ package config import models "github.com/pojntfx/stfs/internal/db/sqlite/models/metadata" type HeaderEvent struct { - Type int + Type string Indexed bool Header *models.Header }