Giter Site home page Giter Site logo

Comments (4)

paketb0te avatar paketb0te commented on May 17, 2024

Not a bad idea IMO, but I am not sure how we can build that - somehow we'd need to know whether a "word" is an argument to a previous command, or if it is already the next command to execute πŸ€”

To illustrate:

git_sim add foo.py commit stash pop

It might be kinda easy to figure out that foo.py is a file name (but what about files without extension?) and not a command, but how would we know if pop is a subcommand of stash, or a command on it's own?

I guess this might be doable by comparing each word to all command names and comparing it to "where in the command/subcommand tree are we right now?", but to me it looks not trivial to implement.

from git-sim.

paketb0te avatar paketb0te commented on May 17, 2024

The simple case where each command takes no arguments is actually surprisingly simple, but of course it does not help with the previously mentioned problem...

import typer

app = typer.Typer()


@app.command(name="bar")
def bar():
    print("bar")


@app.command(name="baz")
def baz():
    print("baz")


@app.command(name="multi")
def multi(cmds: list[str]):
    registered_func_names = [reg_cmd.name for reg_cmd in app.registered_commands]
    for cmd in cmds:
        if cmd in registered_func_names:
            func = globals()[cmd]
            func()
        else:
            print(f"'{cmd}' is not a valid command, skipping...")


if __name__ == "__main__":
    app()
$ python foo.py multi one two bar foo baz baz boo bar
'one' is not a valid command, skipping...
'two' is not a valid command, skipping...
bar
'foo' is not a valid command, skipping...
baz
baz
'boo' is not a valid command, skipping...
bar

from git-sim.

jygastaud avatar jygastaud commented on May 17, 2024

Not a bad idea IMO, but I am not sure how we can build that - somehow we'd need to know whether a "word" is an argument to a previous command, or if it is already the next command to execute thinking

I can imagine at least 3 different ways to handle that :

  1. Force seperator and/or quote each git command inside your line
    You exemple will become
    git_sim "add foo.py" "commit" "stash" "pop"
    
  2. Read a file that contain 1 command per line and just iterate over the file (sounds the easiest way for me)
  3. make git-sim "interactive" so you can run git-sim -i then enter a command, press enter, an other command, press enter…
    That is easy for small workflow but not that good from a UX perspective

from git-sim.

initialcommit-io avatar initialcommit-io commented on May 17, 2024

@jygastaud Interesting thought! We might consider this in the future but for now, we have to focus on getting full coverage of the most common Git commands before we think about chaining together into a larger workflow. Closing for now.

from git-sim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.