-5

I want to build an app that does some functionality when called from command line by typing the app name and the command to be executed. Like for example in git we do the following :

git commit -m "a comment"

The way I think about it is that git app would be called with the arguments commit, -m, and "a comment" and it would process them and does some functionality. My question is whether how I think it's done is actually correct, what is this type of apps called and are there any sources I can read about this?

Note: I am using c++ to program my app.

  • not clear what you are asking. If you just write a console application in either C++ or Java you will know what a console app is. When you execute any program it is typically executed once, until it terminates – 463035818_is_not_an_ai Jan 17 '20 at 15:24
  • Yes, tha's how they work. You have a binary executable called `git` somewhere and this program is run with given arguments. This is called "console program" or "console app". – Yksisarvinen Jan 17 '20 at 15:25
  • Take a look on [boost::program_options](https://www.boost.org/doc/libs/1_58_0/doc/html/program_options.html). – Marek R Jan 17 '20 at 15:33
  • @Yksisarvinen Thank you for your response. What I mean is what this way or style of making console apps is called. Like console apps can forexample have a menu and wait the user's input, but what I want here is to call the app with the arguments in one line – Mohammed S. Yaseen Jan 17 '20 at 15:43
  • 2
    Non-interactive console app? Honestly, I never saw a real console app (as in, used by people worldwide, not written by a student) which would wait for user input (or at least it would be the only option in that app). This makes such an app much harder to use in scripts, and that's the main use of console apps. – Yksisarvinen Jan 17 '20 at 15:47
  • Does this answer your question? [What parameter parser libraries are there for C++?](https://stackoverflow.com/questions/253556/what-parameter-parser-libraries-are-there-for-c) – phd Jan 17 '20 at 15:48
  • https://stackoverflow.com/search?q=%5Bc%2B%2B%5D+command+line+application – phd Jan 17 '20 at 15:48
  • You seem to have something valid in your question, but it's hard to pinpoint. Asking for recommendations is off-topic. Asking multiple questions is off-topic. As for looking for "the" name of something: [What's in a name?](https://www.enotes.com/shakespeare-quotes/what-s-name-that-which-we-call-rose) That which some call a utility by any other name would still be as useful. – JaMiT Jan 17 '20 at 15:51

3 Answers3

2

Did you ever ask yourself why it's either int main() or int main(int argc, char **argv)? That are the arguments. argc is the number of arguments (ARGument Count) and argv is a pointer to an array of this arguments (ARGument Values). The first argument is the application name. In your example git commit -m "a comment" the value of argc is 4 and

  • argv[0]: git
  • argv[1]: commit
  • argv[2]: -m
  • argv[3]: a comment
Thomas Sablik
  • 16,127
  • 7
  • 34
  • 62
0

That is the standard way of handling arguments in Unix/Linux at the very least. Note that programs have access to the name with which they are called, there are a few around that act differently depending on the name they are called with. E.g. vi(1), ex(1), view(1) all resolve to the same executable /usr/bin/vi here (Fedora 31, vim 8.2.109).

vonbrand
  • 11,412
  • 8
  • 32
  • 52
0

As mentioned in comments and other answers, yes the way you think is correct. Those arguments are called "command line arguments".

Take a look at this to learn more about them.

Null3rror
  • 105
  • 7