-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement delete profile command (#12)
* fix typo(givnig -> giving) * Implement delete profile command * Update TODO
- Loading branch information
1 parent
8c814d7
commit 83c84e8
Showing
11 changed files
with
68 additions
and
11 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 |
---|---|---|
|
@@ -4,8 +4,6 @@ | |
|
||
## TODO | ||
### main | ||
* list profiles | ||
* delete profile | ||
* log level | ||
### test | ||
* config | ||
|
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,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 | ||
} |
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
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
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