views:

28

answers:

1

Can / Should MVC be used on a SVN or HG type CLI application? If so, how might one go about this?

I've been trying to come up with a design and I've come to the conclusion that MVC and HG/SVN type interface simply doesn't work together; that they serve separate purposes.

Just to be clear, what I mean by the Hg/SVN type interface is issue a command to run the program, it runs and terminates:

 hg commit -m"my message"

or

 svn up
+2  A: 

What is HTTP? You send a command up to the server. That command is "get me page X".

What is CLI? You send a command to the server. That command is "show me thing Y".

So at the core level, the concepts are very similar: you send a command; the "server" interprets that command against some kind of "model". Then, it morphs the model using some sort of logic (controller) and presents it to you (view).

Unless your CLI application is very simplistic, I'm assuming it has some sort of state. For example, you can go into screen A, and pick a record A1 from the list {A1, A2, A3}. Those records probably come from a database or some flat file.

What would this mean in a Web application? You navigate to a page; the page is shown to you based on some model (there's one class that helps you interact with the database and get a list of records). It's then transformed into HTML by some controller. It's then styled in your view (HTML < table >).

What would it mean in a CLI application? Exactly same thing. Except that your "view" is going to be drastically more simplistic (instead of a separate fancy HTML template file, you'd probably have a sprintf()-type deal)

Alex
MVC does not only apply to HTTP. It is used on non-web page applications all the time. First one that comes to mind is cocoa-touch.
Frank V
Since you are voting 'for' this idea, how would you see the view and controller? Would there be one view (representing the CLI) and one controller, to control the CLI view? Or multiple views / controllers?
Frank V
Yes, obviously, MVC is used all over client applications, too. I was just giving an example that I knew you could relate to (many more folks know Web MVC platforms than client MVC platforms).I'd use multiple views and controllers for CLI - otherwise, why use MVC at all? For SVN, I'd create one view and one controller for each of the commands. For example: "svn update" view would contain something like:Latest Revision {latestRevisionNum}Changed files:{list of changed files}
Alex
Thanks. I understand what you are saying.
Frank V

related questions