# How does \`appium driver\` sub command works under the hood?

**URL:** <https://discuss.appium.io/t/how-does-appium-driver-sub-command-works-under-the-hood/37955>\
**Category:** Tutorials/Documentation\
**Created:** [December 6, 2022, 9:21am UTC](https://discuss.appium.io/t/how-does-appium-driver-sub-command-works-under-the-hood/37955 "2022-12-06T09:21:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sarin\_Suriyakoon](https://discuss.appium.io/user_avatar/discuss.appium.io/sarin_suriyakoon/32/4441_2.png) [@Sarin\_Suriyakoon](https://discuss.appium.io/u/Sarin_Suriyakoon)\
**Post date:** [December 6, 2022, 9:21am UTC](https://discuss.appium.io/t/how-does-appium-driver-sub-command-works-under-the-hood/37955/1 "2022-12-06T09:21:37Z")

</div>

I am recently looking into how appium works and wonder how the subcommand gets picked up by the source code.

For example these commands,

```auto
appium driver install flutter

```

```auto
appium driver install xcuitest

```

I trace it back to `packages/appium/lib/main.js` then I see `main` calls for `init` function and pas the args. Is the args contain all the `sub command`? I seem to lose track after that. Not really sure where `init` is using all the `sub command` and how `init` works.

I would appreciate it if you share more about how `main` and `init` work.

Cheers!

---

<div class="post-metadata">

**Author:** ![mykola-mokhnach](https://discuss.appium.io/user_avatar/discuss.appium.io/mykola-mokhnach/32/4578_2.png) [@mykola-mokhnach](https://discuss.appium.io/u/mykola-mokhnach)\
**Post date:** [December 6, 2022, 10:59am UTC](https://discuss.appium.io/t/how-does-appium-driver-sub-command-works-under-the-hood/37955/2 "2022-12-06T10:59:13Z")

</div>

You are right. The argument parsing logic lies in the `init` function.  
This function:

- resolves Appium home folder to load extensions and drivers from
- sets up modules load path for extensions and drivers being loaded
- parses command line arguments (either from CLI or a config file)
- creates server instance and prepares parsed config arguments if given arguments are related to the server
- passes arguments to the appropriate driver if needed

Consider checking the ArgParser class to get more info about how command line arguments are being parsed

---

<div class="post-metadata">

**Author:** ![mykola-mokhnach](https://discuss.appium.io/user_avatar/discuss.appium.io/mykola-mokhnach/32/4578_2.png) [@mykola-mokhnach](https://discuss.appium.io/u/mykola-mokhnach)\
**Post date:** [December 6, 2022, 11:00am UTC](https://discuss.appium.io/t/how-does-appium-driver-sub-command-works-under-the-hood/37955/3 "2022-12-06T11:00:38Z")

</div>

Also check `runExtensionCommand` method implemntation to know more about `driver` or `plugin` subcommands processing
