Skip to content

Commit

Permalink
Implement delete profile command (#12)
Browse files Browse the repository at this point in the history
* fix typo(givnig -> giving)

* Implement delete profile command

* Update TODO
  • Loading branch information
corrupt952 authored Nov 7, 2021
1 parent 8c814d7 commit 83c84e8
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 11 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

## TODO
### main
* list profiles
* delete profile
* log level
### test
* config
Expand Down
2 changes: 1 addition & 1 deletion command/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
58 changes: 58 additions & 0 deletions command/delete.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion command/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
2 changes: 1 addition & 1 deletion command/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
2 changes: 1 addition & 1 deletion command/kill.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
4 changes: 2 additions & 2 deletions command/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion command/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
2 changes: 1 addition & 1 deletion command/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
2 changes: 1 addition & 1 deletion command/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}, "")
Expand Down

0 comments on commit 83c84e8

Please sign in to comment.