Skip to content

Delete files in gists #7517

Description

@dardo82

Describe the feature or problem you’d like to solve

Files can't be deleted in gists...

Proposed solution

Add the -d option to gist edit.

Additional context

Interactive if no file is specified?

Activity

  1. williammartin commented on May 31, 2023

    @williammartin
    Member

    Hi @dardo82, thanks for the enhancement request. This sounds like a sensible feature to me except that gist edit already has a -d flag (so let's just pick -r / --remove-file for the moment since that's what it is called in the UI). Let me see if I've got this right:

    Non-interactive mode

    ➜  gh gist edit {<id> | <url>} -r my_file.txt

    Interactive mode

    ➜  gh gist edit {<id> | <url>} -r
    ? Select a file to delete  [Use arrows to move, type to filter]
    > my_file.txt  about 1 minute ago
      option.rb  about 3 months ago

    Is that what you had in mind?

    I'd also love to hear a bit more about your use case, do you usually work with gists from the command line, are you scripting something, etc. Cheers!

  2. added
    more-info-neededMore info needed from user/contributor
    and removed on May 31, 2023
  3. dardo82 commented on May 31, 2023

    @dardo82
    Author

    Removal is the last one missing from the basic set of operations called CRUD, no?

  4. williammartin commented on May 31, 2023

    @williammartin
    Member

    Yes I think that's true. I'm not sure how it relates to my previous comment though.

  5. dardo82 commented on May 31, 2023

    @dardo82
    Author

    How hard will it be to add this option?
    I'm OK with your proposed design for it.

  6. williammartin commented on May 31, 2023

    @williammartin
    Member

    From the docs for updating a gist:

    The gist files to be updated, renamed, or deleted. Each key must match the current filename (including extension) of the targeted gist file. For example: hello.py. To delete a file, set the whole file to null. For example: hello.py : null.

    I think this feature would iterating over the files in the fetched gist, and when the Filename matches the provided one, set the value in the Files map with that key to nil and then update the gist. So, I think this shouldn't be too hard (but this is the first time I've looked at this code).

    I'm inclined to accept this as a reasonable enhancement and mark this as help wanted so that someone in the community can pick it up. However, since I'm new to this project, I'm going to tag @vilmibm for his opinions as he has spent more time around the gist commands.

  7. vilmibm commented on May 31, 2023

    @vilmibm
    Contributor

    This seems reasonable to me! The absence of this feature is an oversight and not intentional.

  8. dardo82 commented on Jun 1, 2023

    @dardo82
    Author

    So the gh api gist command can do it?
    But gh gist edit -r would be simpler.

  9. reopened this on Jun 1, 2023
  10. added and removed
    more-info-neededMore info needed from user/contributor
    on Jun 1, 2023
  11. williammartin commented on Jun 1, 2023

    @williammartin
    Member

    A couple of further questions we should answer.

    What should happen if you provide the -r flag with other flags?

    ➜  gh gist edit {<id> | <url>} -r my_file_to_delete.txt -a my_file_to_add.txt

    Should we treat this as an error or try to handle it? What would we do if this were interactive?

    Should we support deleting multiple files in one command?

    ➜  gh gist edit {<id> | <url>} -r file_1.txt -d file_2.txt

    Proposal

    Given that:

    • gist edit -a file_1.txt -a file_2.txt only adds one file (silently ignoring the other, just due to how flag parsing is done)
    • gh gist edit -f file2.txt -a file3.txt doesn't respect both flags (-f is silently ignored)

    I would be inclined to scope this work to single file deletion, and an explicit error if -r is provided with other flags.

    @vilmibm for any extra thoughts.

  12. dardo82 commented on Jun 1, 2023

    @dardo82
    Author

    Yeah, be consistent with the design of other options if there aren't specific reasons for it to be different...

  13. vilmibm commented on Jun 6, 2023

    @vilmibm
    Contributor

    I'm +1 on scoping to single file deletion as well as not allowing -r with other flags.

  14. williammartin commented on Jun 23, 2023

    @williammartin
    Member

    As discussed, this has been implemented without the interactive flow. Thanks all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementa request to improve CLIhelp wantedContributions welcome

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions