-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
513 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// +build darwin | ||
|
||
package common | ||
|
||
const ( | ||
LineBreak = "\n" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// +build !windows,!darwin | ||
|
||
package common | ||
|
||
const ( | ||
LineBreak = "\n" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// +build windows | ||
|
||
package common | ||
|
||
const ( | ||
LineBreak = "\r\n" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package entry | ||
|
||
import ( | ||
"context" | ||
dcm "gabyx/githooks/apps/dialog/cmd/common" | ||
"gabyx/githooks/apps/dialog/gui" | ||
res "gabyx/githooks/apps/dialog/result" | ||
set "gabyx/githooks/apps/dialog/settings" | ||
ccm "gabyx/githooks/cmd/common" | ||
"os" | ||
"time" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func handleResult(ctx *dcm.CmdContext, res *res.Entry, err error) error { | ||
return dcm.HandleGeneralResult(ctx, &res.General, err, func() error { | ||
_, err := os.Stdout.WriteString(res.Text + dcm.LineBreak) | ||
|
||
return err | ||
}, nil) | ||
} | ||
|
||
func NewCmd(ctx *dcm.CmdContext) *cobra.Command { | ||
|
||
settings := set.Entry{} | ||
var timeout uint | ||
|
||
cmd := &cobra.Command{ | ||
Use: "entry", | ||
Short: "Shows a entry dialog.", | ||
Long: `Shows a entry dialog similar to 'zenity'. | ||
See 'https://help.gnome.org/users/zenity/3.32' for details.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
|
||
var cancel func() | ||
var cont context.Context | ||
|
||
if timeout > 0 { | ||
cont, cancel = context.WithTimeout(context.Background(), time.Duration(timeout)*time.Second) | ||
defer cancel() | ||
} | ||
|
||
res, err := gui.ShowEntry(cont, &settings) | ||
err = handleResult(ctx, &res, err) | ||
ctx.Log.AssertNoErrorPanic(err, "Dialog failed") | ||
}} | ||
|
||
cmd.Flags().UintVar(&timeout, "timeout", 0, "Timeout for the dialog") | ||
|
||
dcm.AddFlagsEntry(cmd, &settings) | ||
ccm.SetCommandDefaults(ctx.Log, cmd) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package notify | ||
|
||
import ( | ||
"context" | ||
dcm "gabyx/githooks/apps/dialog/cmd/common" | ||
"gabyx/githooks/apps/dialog/gui" | ||
set "gabyx/githooks/apps/dialog/settings" | ||
ccm "gabyx/githooks/cmd/common" | ||
"time" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func handleResult(ctx *dcm.CmdContext, err error) error { | ||
if err == nil { | ||
ctx.ExitCode = 0 | ||
} | ||
|
||
return err | ||
} | ||
|
||
func NewCmd(ctx *dcm.CmdContext) *cobra.Command { | ||
|
||
settings := set.Notification{} | ||
var timeout uint | ||
|
||
cmd := &cobra.Command{ | ||
Use: "notify", | ||
Short: "Shows a notification.", | ||
Long: `Shows a notification similar to 'zenity'. | ||
See 'https://help.gnome.org/users/zenity/3.32' for details.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
|
||
var cancel func() | ||
var cont context.Context | ||
|
||
if timeout > 0 { | ||
cont, cancel = context.WithTimeout(context.Background(), time.Duration(timeout)*time.Second) | ||
defer cancel() | ||
} | ||
|
||
err := gui.ShowNotification(cont, &settings) | ||
err = handleResult(ctx, err) | ||
ctx.Log.AssertNoErrorPanic(err, "Dialog failed") | ||
}} | ||
|
||
cmd.Flags().UintVar(&timeout, "timeout", 0, "Timeout for the dialog") | ||
|
||
dcm.AddFlagsNotification(cmd, &settings) | ||
ccm.SetCommandDefaults(ctx.Log, cmd) | ||
|
||
return cmd | ||
} |
Oops, something went wrong.