diff --git a/README.md b/README.md index 56c2f8a..83e650d 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,6 @@ ## TODO ### main -* list profiles -* delete profile * log level ### test * config diff --git a/command/attach.go b/command/attach.go index 3aa660c..0b0e831 100644 --- a/command/attach.go +++ b/command/attach.go @@ -28,7 +28,7 @@ func (*AttachCommand) Synopsis() string { return "attach tmux session" } -// Usage returns a long string explaining AttachCommand and givinig usage. +// Usage returns a long string explaining AttachCommand and giving usage. func (*AttachCommand) Usage() string { return "kill: tmuxist kill [-profile profile]\n" } diff --git a/command/delete.go b/command/delete.go new file mode 100644 index 0000000..af8c127 --- /dev/null +++ b/command/delete.go @@ -0,0 +1,58 @@ +package command + +import ( + "context" + "flag" + "fmt" + "os" + + "github.com/google/subcommands" + + "tmuxist/config" + "tmuxist/logger" +) + +// DeleteCommand represents a print startup script command. +type DeleteCommand struct { + profile string +} + +// Name returns the name of DeleteCommand. +func (*DeleteCommand) Name() string { + return "delete" +} + +// Synopsis returns a short string describing DeleteCommand. +func (*DeleteCommand) Synopsis() string { + return "delete tmuxist configuration" +} + +// Usage returns a long string explaining DeleteCommand and giving usage. +func (*DeleteCommand) Usage() string { + return "delete: tmuxist delete [-profile profile]\n" +} + +// SetFlags adds the flags for DeleteCommand to the specified set. +func (cmd *DeleteCommand) SetFlags(f *flag.FlagSet) { + f.StringVar(&cmd.profile, "profile", config.DefaultProfileName(), "Profile") +} + +// Execute executes print startup script and returns an ExitStatus. +func (cmd *DeleteCommand) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus { + path, err := config.ConfigurationPath(cmd.profile) + if err != nil { + logger.Err(err.Error()) + return subcommands.ExitFailure + } + if _, err := os.Stat(path); err != nil { + logger.Err(err.Error()) + return subcommands.ExitFailure + } + if err := os.Remove(path); err != nil { + logger.Err(err.Error()) + return subcommands.ExitFailure + } + + fmt.Println("Delete profile: " + cmd.profile) + return subcommands.ExitSuccess +} diff --git a/command/edit.go b/command/edit.go index a199811..7c9d5e0 100644 --- a/command/edit.go +++ b/command/edit.go @@ -28,7 +28,7 @@ func (*EditCommand) Synopsis() string { return "edit tmuxist configuration" } -// Usage returns a long string explaining EditCommand and givinig usage. +// Usage returns a long string explaining EditCommand and giving usage. func (*EditCommand) Usage() string { return "edit: tmuxist edit [-editor editor] [-profile profile]\n" } diff --git a/command/init.go b/command/init.go index 427f52d..442de5b 100644 --- a/command/init.go +++ b/command/init.go @@ -30,7 +30,7 @@ func (*InitCommand) Synopsis() string { return "initialize tmuxist configuration" } -// Usage returns a long string explaining InitCommand and givinig usage. +// Usage returns a long string explaining InitCommand and giving usage. func (*InitCommand) Usage() string { return "init: tmuxist init [-profile profile]\n" } diff --git a/command/kill.go b/command/kill.go index 8001deb..8d009b1 100644 --- a/command/kill.go +++ b/command/kill.go @@ -28,7 +28,7 @@ func (*KillCommand) Synopsis() string { return "kill tmux session" } -// Usage returns a long string explaining KillCommand and givinig usage. +// Usage returns a long string explaining KillCommand and giving usage. func (*KillCommand) Usage() string { return "kill: tmuxist kill [-profile profile]\n" } diff --git a/command/list.go b/command/list.go index c994856..78a3653 100644 --- a/command/list.go +++ b/command/list.go @@ -25,9 +25,9 @@ func (*ListCommand) Synopsis() string { return "List tmuxist profiles" } -// Usage returns a long string explaining ListCommand and givinig usage. +// Usage returns a long string explaining ListCommand and giving usage. func (*ListCommand) Usage() string { - return "list: show tmuxist profiles\n" + return "list: tmuxist list\n" } // SetFlags adds the flags for ListCommand to the specified set. diff --git a/command/print.go b/command/print.go index 6c4e2b3..b74a8ff 100644 --- a/command/print.go +++ b/command/print.go @@ -27,7 +27,7 @@ func (*PrintCommand) Synopsis() string { return "print tmuxist configuration" } -// Usage returns a long string explaining PrintCommand and givinig usage. +// Usage returns a long string explaining PrintCommand and giving usage. func (*PrintCommand) Usage() string { return "print: tmuxist print [-profile profile]\n" } diff --git a/command/start.go b/command/start.go index 26713fd..0ae14a5 100644 --- a/command/start.go +++ b/command/start.go @@ -28,7 +28,7 @@ func (*StartCommand) Synopsis() string { return "start tmux session" } -// Usage returns a long string explaining StartCommand and givinig usage. +// Usage returns a long string explaining StartCommand and giving usage. func (*StartCommand) Usage() string { return "start: tmuxist start [-profile profile]\n" } diff --git a/command/version.go b/command/version.go index 1a9b0e7..ff11925 100644 --- a/command/version.go +++ b/command/version.go @@ -25,7 +25,7 @@ func (*VersionCommand) Synopsis() string { return "Print tmuxist version" } -// Usage returns a long string explaining VersionCommand and givinig usage. +// Usage returns a long string explaining VersionCommand and giving usage. func (*VersionCommand) Usage() string { return "version: tmuxist version\n" } diff --git a/main.go b/main.go index dfececd..a12c82d 100644 --- a/main.go +++ b/main.go @@ -17,6 +17,7 @@ func main() { subcommands.Register(&command.ListCommand{}, "") subcommands.Register(&command.InitCommand{}, "") subcommands.Register(&command.EditCommand{}, "") + subcommands.Register(&command.DeleteCommand{}, "") subcommands.Register(&command.PrintCommand{}, "") subcommands.Register(&command.StartCommand{}, "") subcommands.Register(&command.KillCommand{}, "")