From f72b18496b508c23cee6fa99d764cfe59208515c Mon Sep 17 00:00:00 2001 From: Rafael Passos Date: Wed, 24 Oct 2018 18:36:39 -0300 Subject: [PATCH] moved cleaner function to util/interrupt --- commands/add.go | 4 ++-- commands/bridge.go | 4 ++-- commands/bridge_configure.go | 4 ++-- commands/bridge_pull.go | 4 ++-- commands/bridge_rm.go | 4 ++-- commands/comment.go | 4 ++-- commands/comment_add.go | 4 ++-- commands/deselect.go | 4 ++-- commands/label.go | 4 ++-- commands/label_add.go | 4 ++-- commands/label_rm.go | 4 ++-- commands/ls-labels.go | 4 ++-- commands/ls.go | 4 ++-- commands/pull.go | 4 ++-- commands/push.go | 4 ++-- commands/select.go | 4 ++-- commands/show.go | 4 ++-- commands/status.go | 4 ++-- commands/status_close.go | 4 ++-- commands/status_open.go | 4 ++-- commands/termui.go | 4 ++-- commands/title.go | 4 ++-- commands/title_edit.go | 4 ++-- {cleaner => util/interrupt}/cleaner.go | 6 +++--- 24 files changed, 49 insertions(+), 49 deletions(-) rename {cleaner => util/interrupt}/cleaner.go (74%) diff --git a/commands/add.go b/commands/add.go index e2650406b3be6165431e6a007ddc13719291d292..54ede1260daaa6f3e0cd9d12725ec9ca970a7a3b 100644 --- a/commands/add.go +++ b/commands/add.go @@ -4,8 +4,8 @@ import ( "fmt" "github.com/MichaelMure/git-bug/cache" - "github.com/MichaelMure/git-bug/cleaner" "github.com/MichaelMure/git-bug/input" + "github.com/MichaelMure/git-bug/util/interrupt" "github.com/spf13/cobra" ) @@ -23,7 +23,7 @@ func runAddBug(cmd *cobra.Command, args []string) error { return err } defer backend.Close() - cleaner.Register(backend.Close) + interrupt.RegisterCleaner(backend.Close) if addMessageFile != "" && addMessage == "" { addTitle, addMessage, err = input.BugCreateFileInput(addMessageFile) diff --git a/commands/bridge.go b/commands/bridge.go index ffba2b9d8c94d24b98f4734cd1b6cfae3ba7fdbd..a473776d7eaa1692e93d5ddb355c1ffe3da4b0fc 100644 --- a/commands/bridge.go +++ b/commands/bridge.go @@ -5,7 +5,7 @@ import ( "github.com/MichaelMure/git-bug/bridge" "github.com/MichaelMure/git-bug/cache" - "github.com/MichaelMure/git-bug/cleaner" + "github.com/MichaelMure/git-bug/util/interrupt" "github.com/spf13/cobra" ) @@ -15,7 +15,7 @@ func runBridge(cmd *cobra.Command, args []string) error { return err } defer backend.Close() - cleaner.Register(backend.Close) + interrupt.RegisterCleaner(backend.Close) configured, err := bridge.ConfiguredBridges(backend) if err != nil { diff --git a/commands/bridge_configure.go b/commands/bridge_configure.go index c4d41c742266104851b23cf7850d1e764748f6a7..ef499f1ff59b97dee3fe05cc98fe6706ca228c5a 100644 --- a/commands/bridge_configure.go +++ b/commands/bridge_configure.go @@ -9,7 +9,7 @@ import ( "github.com/MichaelMure/git-bug/bridge" "github.com/MichaelMure/git-bug/cache" - "github.com/MichaelMure/git-bug/cleaner" + "github.com/MichaelMure/git-bug/util/interrupt" "github.com/spf13/cobra" ) @@ -19,7 +19,7 @@ func runBridgeConfigure(cmd *cobra.Command, args []string) error { return err } defer backend.Close() - cleaner.Register(backend.Close) + interrupt.RegisterCleaner(backend.Close) target, err := promptTarget() if err != nil { diff --git a/commands/bridge_pull.go b/commands/bridge_pull.go index f7e2acf050bc02d134aed21c18aae4390e83600a..669a67133b0ddd6b26386c7bf23d7d0fda841368 100644 --- a/commands/bridge_pull.go +++ b/commands/bridge_pull.go @@ -4,7 +4,7 @@ import ( "github.com/MichaelMure/git-bug/bridge" "github.com/MichaelMure/git-bug/bridge/core" "github.com/MichaelMure/git-bug/cache" - "github.com/MichaelMure/git-bug/cleaner" + "github.com/MichaelMure/git-bug/util/interrupt" "github.com/spf13/cobra" ) @@ -14,7 +14,7 @@ func runBridgePull(cmd *cobra.Command, args []string) error { return err } defer backend.Close() - cleaner.Register(backend.Close) + interrupt.RegisterCleaner(backend.Close) var b *core.Bridge diff --git a/commands/bridge_rm.go b/commands/bridge_rm.go index 92f1b3c50713f242d03a78bf97a10293730ca91c..172fc0d8d2ff214789e69f80565542e787679ed6 100644 --- a/commands/bridge_rm.go +++ b/commands/bridge_rm.go @@ -3,7 +3,7 @@ package commands import ( "github.com/MichaelMure/git-bug/bridge" "github.com/MichaelMure/git-bug/cache" - "github.com/MichaelMure/git-bug/cleaner" + "github.com/MichaelMure/git-bug/util/interrupt" "github.com/spf13/cobra" ) @@ -13,7 +13,7 @@ func runBridgeRm(cmd *cobra.Command, args []string) error { return err } defer backend.Close() - cleaner.Register(backend.Close) + interrupt.RegisterCleaner(backend.Close) err = bridge.RemoveBridges(backend, args[0]) if err != nil { diff --git a/commands/comment.go b/commands/comment.go index f644a23f35f1ec91711e6887316bee844d52413c..89378da30271c5ad746d545356fc059ecd72c9af 100644 --- a/commands/comment.go +++ b/commands/comment.go @@ -5,9 +5,9 @@ import ( "github.com/MichaelMure/git-bug/bug" "github.com/MichaelMure/git-bug/cache" - "github.com/MichaelMure/git-bug/cleaner" "github.com/MichaelMure/git-bug/commands/select" "github.com/MichaelMure/git-bug/util/colors" + "github.com/MichaelMure/git-bug/util/interrupt" "github.com/MichaelMure/git-bug/util/text" "github.com/spf13/cobra" ) @@ -18,7 +18,7 @@ func runComment(cmd *cobra.Command, args []string) error { return err } defer backend.Close() - cleaner.Register(backend.Close) + interrupt.RegisterCleaner(backend.Close) b, args, err := _select.ResolveBug(backend, args) if err != nil { diff --git a/commands/comment_add.go b/commands/comment_add.go index 3266e9414f95595ec92f75e4fa65df167eba9666..58408bc58115300d1fc5db36ce9b61dfd92fd371 100644 --- a/commands/comment_add.go +++ b/commands/comment_add.go @@ -4,9 +4,9 @@ import ( "fmt" "github.com/MichaelMure/git-bug/cache" - "github.com/MichaelMure/git-bug/cleaner" "github.com/MichaelMure/git-bug/commands/select" "github.com/MichaelMure/git-bug/input" + "github.com/MichaelMure/git-bug/util/interrupt" "github.com/spf13/cobra" ) @@ -21,7 +21,7 @@ func runCommentAdd(cmd *cobra.Command, args []string) error { return err } defer backend.Close() - cleaner.Register(backend.Close) + interrupt.RegisterCleaner(backend.Close) b, args, err := _select.ResolveBug(backend, args) if err != nil { diff --git a/commands/deselect.go b/commands/deselect.go index d04e7bc1a5653927cb917b00bfc36f92d2464141..210f158c1b7638d651c5a09aae669163ab8fe1dc 100644 --- a/commands/deselect.go +++ b/commands/deselect.go @@ -2,8 +2,8 @@ package commands import ( "github.com/MichaelMure/git-bug/cache" - "github.com/MichaelMure/git-bug/cleaner" "github.com/MichaelMure/git-bug/commands/select" + "github.com/MichaelMure/git-bug/util/interrupt" "github.com/spf13/cobra" ) @@ -13,7 +13,7 @@ func runDeselect(cmd *cobra.Command, args []string) error { return err } defer backend.Close() - cleaner.Register(backend.Close) + interrupt.RegisterCleaner(backend.Close) err = _select.Clear(backend) if err != nil { diff --git a/commands/label.go b/commands/label.go index 75a034f84ffd283fa2188d44a03ea386252f4cdd..58ccc299f098c3a9638ace473f7f682474a91311 100644 --- a/commands/label.go +++ b/commands/label.go @@ -4,8 +4,8 @@ import ( "fmt" "github.com/MichaelMure/git-bug/cache" - "github.com/MichaelMure/git-bug/cleaner" "github.com/MichaelMure/git-bug/commands/select" + "github.com/MichaelMure/git-bug/util/interrupt" "github.com/spf13/cobra" ) @@ -15,7 +15,7 @@ func runLabel(cmd *cobra.Command, args []string) error { return err } defer backend.Close() - cleaner.Register(backend.Close) + interrupt.RegisterCleaner(backend.Close) b, args, err := _select.ResolveBug(backend, args) if err != nil { diff --git a/commands/label_add.go b/commands/label_add.go index 4fe6b3279366bd0e74ee5892b3c5b13ad84880bd..f04ed7d67514f5e26b51e86aa1b72e4145e2537c 100644 --- a/commands/label_add.go +++ b/commands/label_add.go @@ -4,8 +4,8 @@ import ( "fmt" "github.com/MichaelMure/git-bug/cache" - "github.com/MichaelMure/git-bug/cleaner" "github.com/MichaelMure/git-bug/commands/select" + "github.com/MichaelMure/git-bug/util/interrupt" "github.com/spf13/cobra" ) @@ -15,7 +15,7 @@ func runLabelAdd(cmd *cobra.Command, args []string) error { return err } defer backend.Close() - cleaner.Register(backend.Close) + interrupt.RegisterCleaner(backend.Close) b, args, err := _select.ResolveBug(backend, args) if err != nil { diff --git a/commands/label_rm.go b/commands/label_rm.go index b8cc9620854c874119370216f78d876422ce8f98..36051ba197f1fd4fd72641ddba8cebba63c8d8a7 100644 --- a/commands/label_rm.go +++ b/commands/label_rm.go @@ -4,8 +4,8 @@ import ( "fmt" "github.com/MichaelMure/git-bug/cache" - "github.com/MichaelMure/git-bug/cleaner" "github.com/MichaelMure/git-bug/commands/select" + "github.com/MichaelMure/git-bug/util/interrupt" "github.com/spf13/cobra" ) @@ -15,7 +15,7 @@ func runLabelRm(cmd *cobra.Command, args []string) error { return err } defer backend.Close() - cleaner.Register(backend.Close) + interrupt.RegisterCleaner(backend.Close) b, args, err := _select.ResolveBug(backend, args) if err != nil { diff --git a/commands/ls-labels.go b/commands/ls-labels.go index 525303e00aeb31521286abf5ff0067b101e53098..ef2c95bcc3fc866551165ccae4ecce3c4944de61 100644 --- a/commands/ls-labels.go +++ b/commands/ls-labels.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/MichaelMure/git-bug/cache" - "github.com/MichaelMure/git-bug/cleaner" + "github.com/MichaelMure/git-bug/util/interrupt" "github.com/spf13/cobra" ) @@ -14,7 +14,7 @@ func runLsLabel(cmd *cobra.Command, args []string) error { return err } defer backend.Close() - cleaner.Register(backend.Close) + interrupt.RegisterCleaner(backend.Close) labels := backend.ValidLabels() diff --git a/commands/ls.go b/commands/ls.go index a25aa5829afc4f304b04525391bd8d4616d664d3..2f621bc5aaf2f387f30cdbf315c732e56547cbe4 100644 --- a/commands/ls.go +++ b/commands/ls.go @@ -6,8 +6,8 @@ import ( "github.com/MichaelMure/git-bug/bug" "github.com/MichaelMure/git-bug/cache" - "github.com/MichaelMure/git-bug/cleaner" "github.com/MichaelMure/git-bug/util/colors" + "github.com/MichaelMure/git-bug/util/interrupt" "github.com/spf13/cobra" ) @@ -26,7 +26,7 @@ func runLsBug(cmd *cobra.Command, args []string) error { return err } defer backend.Close() - cleaner.Register(backend.Close) + interrupt.RegisterCleaner(backend.Close) var query *cache.Query if len(args) >= 1 { diff --git a/commands/pull.go b/commands/pull.go index cfdcd7719576e72ce9d035a313826e09e5f851ce..67c2a3398a0a8a7fab90d6f16097d28c411c6c88 100644 --- a/commands/pull.go +++ b/commands/pull.go @@ -6,7 +6,7 @@ import ( "github.com/MichaelMure/git-bug/bug" "github.com/MichaelMure/git-bug/cache" - "github.com/MichaelMure/git-bug/cleaner" + "github.com/MichaelMure/git-bug/util/interrupt" "github.com/spf13/cobra" ) @@ -25,7 +25,7 @@ func runPull(cmd *cobra.Command, args []string) error { return err } defer backend.Close() - cleaner.Register(backend.Close) + interrupt.RegisterCleaner(backend.Close) fmt.Println("Fetching remote ...") diff --git a/commands/push.go b/commands/push.go index 599b55574a66e6d7105d26633b9a18df9d5efb44..0477be60a5545ac6a583aea0fbf67e25a263d254 100644 --- a/commands/push.go +++ b/commands/push.go @@ -5,7 +5,7 @@ import ( "fmt" "github.com/MichaelMure/git-bug/cache" - "github.com/MichaelMure/git-bug/cleaner" + "github.com/MichaelMure/git-bug/util/interrupt" "github.com/spf13/cobra" ) @@ -24,7 +24,7 @@ func runPush(cmd *cobra.Command, args []string) error { return err } defer backend.Close() - cleaner.Register(backend.Close) + interrupt.RegisterCleaner(backend.Close) stdout, err := backend.Push(remote) if err != nil { diff --git a/commands/select.go b/commands/select.go index a519d921da3fdb32f5a6e2dbcadb1f58bd2cdd92..cc6883540cb7f7525b7c65d4e600f5803b82a6aa 100644 --- a/commands/select.go +++ b/commands/select.go @@ -5,8 +5,8 @@ import ( "fmt" "github.com/MichaelMure/git-bug/cache" - "github.com/MichaelMure/git-bug/cleaner" "github.com/MichaelMure/git-bug/commands/select" + "github.com/MichaelMure/git-bug/util/interrupt" "github.com/spf13/cobra" ) @@ -20,7 +20,7 @@ func runSelect(cmd *cobra.Command, args []string) error { return err } defer backend.Close() - cleaner.Register(backend.Close) + interrupt.RegisterCleaner(backend.Close) prefix := args[0] diff --git a/commands/show.go b/commands/show.go index d6c05d87f6c5394de58e40fa96e919f844d2f2ae..86c01a176e3c7e2e890c8bb43a54e254205d1b55 100644 --- a/commands/show.go +++ b/commands/show.go @@ -6,9 +6,9 @@ import ( "strings" "github.com/MichaelMure/git-bug/cache" - "github.com/MichaelMure/git-bug/cleaner" "github.com/MichaelMure/git-bug/commands/select" "github.com/MichaelMure/git-bug/util/colors" + "github.com/MichaelMure/git-bug/util/interrupt" "github.com/spf13/cobra" ) @@ -18,7 +18,7 @@ func runShowBug(cmd *cobra.Command, args []string) error { return err } defer backend.Close() - cleaner.Register(backend.Close) + interrupt.RegisterCleaner(backend.Close) b, args, err := _select.ResolveBug(backend, args) if err != nil { diff --git a/commands/status.go b/commands/status.go index bdd6dd4a8222ed67d99a7d7fa5054a6a697439e2..7928628a751eab19cf6b8daa1faeeb319266d060 100644 --- a/commands/status.go +++ b/commands/status.go @@ -4,8 +4,8 @@ import ( "fmt" "github.com/MichaelMure/git-bug/cache" - "github.com/MichaelMure/git-bug/cleaner" "github.com/MichaelMure/git-bug/commands/select" + "github.com/MichaelMure/git-bug/util/interrupt" "github.com/spf13/cobra" ) @@ -15,7 +15,7 @@ func runStatus(cmd *cobra.Command, args []string) error { return err } defer backend.Close() - cleaner.Register(backend.Close) + interrupt.RegisterCleaner(backend.Close) b, args, err := _select.ResolveBug(backend, args) if err != nil { diff --git a/commands/status_close.go b/commands/status_close.go index 823d98b5d06aca153cd33838e3d153999eb42f44..2b4f9602c307fd9e7dc61a0f92fbb9784a876674 100644 --- a/commands/status_close.go +++ b/commands/status_close.go @@ -2,8 +2,8 @@ package commands import ( "github.com/MichaelMure/git-bug/cache" - "github.com/MichaelMure/git-bug/cleaner" "github.com/MichaelMure/git-bug/commands/select" + "github.com/MichaelMure/git-bug/util/interrupt" "github.com/spf13/cobra" ) @@ -13,7 +13,7 @@ func runStatusClose(cmd *cobra.Command, args []string) error { return err } defer backend.Close() - cleaner.Register(backend.Close) + interrupt.RegisterCleaner(backend.Close) b, args, err := _select.ResolveBug(backend, args) if err != nil { diff --git a/commands/status_open.go b/commands/status_open.go index 0413d2b708a32c9f79bcebe46c084d1baf4e133e..5e3029e218313b7b9825878fa2dddc553fc913b8 100644 --- a/commands/status_open.go +++ b/commands/status_open.go @@ -2,8 +2,8 @@ package commands import ( "github.com/MichaelMure/git-bug/cache" - "github.com/MichaelMure/git-bug/cleaner" "github.com/MichaelMure/git-bug/commands/select" + "github.com/MichaelMure/git-bug/util/interrupt" "github.com/spf13/cobra" ) @@ -13,7 +13,7 @@ func runStatusOpen(cmd *cobra.Command, args []string) error { return err } defer backend.Close() - cleaner.Register(backend.Close) + interrupt.RegisterCleaner(backend.Close) b, args, err := _select.ResolveBug(backend, args) if err != nil { diff --git a/commands/termui.go b/commands/termui.go index d3dbc7330a3bf41b671493be48edef229ad1a8a6..4a029d6c256696544a6c0381c5013f16fdcb7c3a 100644 --- a/commands/termui.go +++ b/commands/termui.go @@ -2,8 +2,8 @@ package commands import ( "github.com/MichaelMure/git-bug/cache" - "github.com/MichaelMure/git-bug/cleaner" "github.com/MichaelMure/git-bug/termui" + "github.com/MichaelMure/git-bug/util/interrupt" "github.com/spf13/cobra" ) @@ -13,7 +13,7 @@ func runTermUI(cmd *cobra.Command, args []string) error { return err } defer backend.Close() - cleaner.Register(backend.Close) + interrupt.RegisterCleaner(backend.Close) return termui.Run(backend) } diff --git a/commands/title.go b/commands/title.go index 37db03ddeb3ad8b413d63db288c54df25e994542..c9157a7066201ebffbb66e55fcac934df459be5e 100644 --- a/commands/title.go +++ b/commands/title.go @@ -4,8 +4,8 @@ import ( "fmt" "github.com/MichaelMure/git-bug/cache" - "github.com/MichaelMure/git-bug/cleaner" "github.com/MichaelMure/git-bug/commands/select" + "github.com/MichaelMure/git-bug/util/interrupt" "github.com/spf13/cobra" ) @@ -15,7 +15,7 @@ func runTitle(cmd *cobra.Command, args []string) error { return err } defer backend.Close() - cleaner.Register(backend.Close) + interrupt.RegisterCleaner(backend.Close) b, args, err := _select.ResolveBug(backend, args) if err != nil { diff --git a/commands/title_edit.go b/commands/title_edit.go index de9a55ab916a822033966dacef309a7c5ab30d00..6bbd1b0a086f634f86f50ddbca5534d50af2a9cb 100644 --- a/commands/title_edit.go +++ b/commands/title_edit.go @@ -4,9 +4,9 @@ import ( "fmt" "github.com/MichaelMure/git-bug/cache" - "github.com/MichaelMure/git-bug/cleaner" "github.com/MichaelMure/git-bug/commands/select" "github.com/MichaelMure/git-bug/input" + "github.com/MichaelMure/git-bug/util/interrupt" "github.com/spf13/cobra" ) @@ -20,7 +20,7 @@ func runTitleEdit(cmd *cobra.Command, args []string) error { return err } defer backend.Close() - cleaner.Register(backend.Close) + interrupt.RegisterCleaner(backend.Close) b, args, err := _select.ResolveBug(backend, args) if err != nil { diff --git a/cleaner/cleaner.go b/util/interrupt/cleaner.go similarity index 74% rename from cleaner/cleaner.go rename to util/interrupt/cleaner.go index 595c9fb01c285676d46b48710bba2b433d60c205..dfb8e25b4599064047a7ece62ef404adee764e23 100644 --- a/cleaner/cleaner.go +++ b/util/interrupt/cleaner.go @@ -1,4 +1,4 @@ -package cleaner +package interrupt import ( "fmt" @@ -12,8 +12,8 @@ type Cleaner func() error var cleaners []Cleaner var inactive bool -// Register a cleaner function. When a function is registered, the Signal watcher is started in a goroutine. -func Register(f Cleaner) { +// RegisterCleaner is responsible for regisreting a cleaner function. When a function is registered, the Signal watcher is started in a goroutine. +func RegisterCleaner(f Cleaner) { cleaners = append(cleaners, f) if !inactive { inactive = false