Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding delete command and deprecate eject command #157

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rchojn
Copy link
Contributor

@rchojn rchojn commented Nov 21, 2024

Add delete command and deprecate eject command

Problem

Currently, there's no way to remove specific sauces from a project - the eject command removes all sauces at once.

Solution

Add a new delete command that allows:

  • Deleting a specific sauce by ID
  • Deleting all sauces (replacing eject functionality)

Changes

  • Added new delete command with two modes:
    • jalapeno delete <sauce-id>: Removes specific sauce and its files
    • jalapeno delete --all: Removes all sauces and their files
  • Marked eject command as deprecated with message to use delete --all instead
  • Added unit tests verifying all functionality

Testing

Added comprehensive tests that verify:

  • ✅ Deleting specific sauce:
    • Removes only that sauce's files
    • Keeps other sauces intact
    • Updates sauces.yml correctly
  • ✅ Deleting all sauces:
    • Removes all managed files
    • Removes .jalapeno directory
  • ✅ Error handling:
    • Invalid UUID format
    • Missing required arguments (no ID and no --all flag)
    • Non-existent sauce ID

Example Usage

Delete specific sauce

jalapeno delete 21872763-f48e-4728-bc49-57f5898e098a

Delete all sauces (replaces eject command)

jalapeno delete --all

@@ -278,3 +278,28 @@ func LoadManifest(path string) (*Manifest, error) {

return manifest, nil
}

// SaveSauces saves the given sauces to the project directory
func SaveSauces(projectDir string, sauces []*Sauce) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is no need for this helper function. We should utilize the existing .Save method for Sauce to handle the writing operations. So instead of using this helper function, we should iterate over the sauces slice and use the method:

for _, sauce := range sauces {
  err := sauce.Save(opts.Dir)
  if err != nil {
     ...
  }
}

Use: "eject",
Short: "Remove all Jalapeno-specific files from a project",
Long: "Remove all the files and directories that are for Jalapeno internal use, and leave only the rendered project files.",
Deprecated: "use 'delete --all' instead",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a nice idea to deprecate the command instead of removing it, but since the command is so rarely used we can already remove it completely.

Long: `Delete sauce(s) from the project. This will remove the rendered files and the sauce entry from sauces.yml.
If no sauce ID is provided and --all flag is not set, this command will fail.`,
PreRunE: func(cmd *cobra.Command, args []string) error {
if len(args) > 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Args: cobra.MaximumNArgs(1) should be defined so the user can not provide more than one argument

Example: `# Delete a specific sauce
jalapeno delete 21872763-f48e-4728-bc49-57f5898e098a

# Delete all sauces (same as 'jalapeno eject')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we remove the eject command completely, the note can be removed

return fmt.Errorf("invalid sauce ID: %w", err)
}

sauce, err := recipe.LoadSauceByID(opts.Dir, id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could refactor the LoadSauceByID method so that it accepts the ID as string. This way we can hide the internal mechanism that the ID is actually UUID. Then LoadSauceByID should validate that is the provided string actually UUID and return an error if it wasn't.

func NewDeleteCmd() *cobra.Command {
var opts deleteOptions
var cmd = &cobra.Command{
Use: "delete [SAUCE_ID]",
Copy link
Member

@majori majori Nov 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note: I didn't mention this in the issue description, but you've probably also noticed that at the moment there is no clean way to get the sauce ID other than manually looking it up from the sauces.yml file. Later we could have a command to list all the sauces for easier access to IDs.

We should document how to use this command at the end of the usage page (how to get the sauce ID etc).

Comment on lines +127 to +129
if stat, err := os.Stat(jalapenoPath); os.IsNotExist(err) || !stat.IsDir() {
return fmt.Errorf("'%s' is not a Jalapeno project", opts.Dir)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can check is the directory "a Jalapeno project" by looking the return value of recipe.LoadSauces. If the returned []*Sauce is empty, then we can return an warning "Warning: the directory xxx did not contain any sauces to delete".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also refactor the end-to-end tests to work with this new command.

@majori majori changed the title feature: adding delete command and deprecate eject command feat: adding delete command and deprecate eject command Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants