ArgParse - Nested Commands

Building Command Line Tools with Python, Julia and Nodejs Module 02 - Building Command Line Tools in Python with ArgParse
10 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€65.26
List Price:  €93.23
You save:  €27.97
£55.95
List Price:  £79.94
You save:  £23.98
CA$95.75
List Price:  CA$136.79
You save:  CA$41.04
A$107.23
List Price:  A$153.20
You save:  A$45.96
S$95.15
List Price:  S$135.94
You save:  S$40.78
HK$547.94
List Price:  HK$782.80
You save:  HK$234.86
CHF 63.91
List Price:  CHF 91.30
You save:  CHF 27.39
NOK kr766.40
List Price:  NOK kr1,094.90
You save:  NOK kr328.50
DKK kr486.75
List Price:  DKK kr695.39
You save:  DKK kr208.64
NZ$117.46
List Price:  NZ$167.81
You save:  NZ$50.35
د.إ257.06
List Price:  د.إ367.25
You save:  د.إ110.18
৳7,670.29
List Price:  ৳10,958.03
You save:  ৳3,287.74
₹5,832.01
List Price:  ₹8,331.80
You save:  ₹2,499.79
RM334.37
List Price:  RM477.70
You save:  RM143.32
₦88,678.72
List Price:  ₦126,689.32
You save:  ₦38,010.60
₨19,457.85
List Price:  ₨27,798.13
You save:  ₨8,340.27
฿2,591.43
List Price:  ฿3,702.20
You save:  ฿1,110.77
₺2,274.88
List Price:  ₺3,249.97
You save:  ₺975.09
B$360.25
List Price:  B$514.66
You save:  B$154.41
R1,330.75
List Price:  R1,901.16
You save:  R570.40
Лв127.68
List Price:  Лв182.41
You save:  Лв54.73
₩96,191.02
List Price:  ₩137,421.64
You save:  ₩41,230.61
₪265.67
List Price:  ₪379.55
You save:  ₪113.87
₱4,044.82
List Price:  ₱5,778.57
You save:  ₱1,733.74
¥10,886.62
List Price:  ¥15,552.99
You save:  ¥4,666.36
MX$1,193.70
List Price:  MX$1,705.36
You save:  MX$511.66
QR254.90
List Price:  QR364.16
You save:  QR109.26
P969.33
List Price:  P1,384.82
You save:  P415.49
KSh9,413.65
List Price:  KSh13,448.65
You save:  KSh4,035
E£3,352.26
List Price:  E£4,789.16
You save:  E£1,436.89
ብር3,973.96
List Price:  ብር5,677.33
You save:  ብር1,703.36
Kz58,616.62
List Price:  Kz83,741.62
You save:  Kz25,125
CLP$66,678.07
List Price:  CLP$95,258.47
You save:  CLP$28,580.40
CN¥507.14
List Price:  CN¥724.52
You save:  CN¥217.38
RD$4,110.44
List Price:  RD$5,872.31
You save:  RD$1,761.87
DA9,401.90
List Price:  DA13,431.87
You save:  DA4,029.96
FJ$160.42
List Price:  FJ$229.18
You save:  FJ$68.76
Q543.26
List Price:  Q776.12
You save:  Q232.86
GY$14,630.45
List Price:  GY$20,901.55
You save:  GY$6,271.09
ISK kr9,795.80
List Price:  ISK kr13,994.60
You save:  ISK kr4,198.80
DH709.23
List Price:  DH1,013.23
You save:  DH303.99
L1,246.59
List Price:  L1,780.93
You save:  L534.33
ден4,020.35
List Price:  ден5,743.61
You save:  ден1,723.25
MOP$563.94
List Price:  MOP$805.67
You save:  MOP$241.72
N$1,340.22
List Price:  N$1,914.68
You save:  N$574.46
C$2,572.43
List Price:  C$3,675.06
You save:  C$1,102.63
रु9,316.74
List Price:  रु13,310.19
You save:  रु3,993.45
S/259.29
List Price:  S/370.43
You save:  S/111.14
K265.67
List Price:  K379.55
You save:  K113.87
SAR262.50
List Price:  SAR375.02
You save:  SAR112.51
ZK1,825.88
List Price:  ZK2,608.51
You save:  ZK782.63
L324.76
List Price:  L463.96
You save:  L139.20
Kč1,644.30
List Price:  Kč2,349.11
You save:  Kč704.80
Ft25,615.12
List Price:  Ft36,594.60
You save:  Ft10,979.47
SEK kr760.35
List Price:  SEK kr1,086.27
You save:  SEK kr325.91
ARS$61,118.20
List Price:  ARS$87,315.45
You save:  ARS$26,197.25
Bs482.97
List Price:  Bs689.99
You save:  Bs207.01
COP$272,384.35
List Price:  COP$389,137.18
You save:  COP$116,752.82
₡35,055.79
List Price:  ₡50,081.85
You save:  ₡15,026.05
L1,725.31
List Price:  L2,464.83
You save:  L739.52
₲519,197.15
List Price:  ₲741,742.01
You save:  ₲222,544.85
$U2,684.12
List Price:  $U3,834.62
You save:  $U1,150.50
zł281.58
List Price:  zł402.27
You save:  zł120.69
Already have an account? Log In

Transcript

All right, so welcome back again. So in this first class session of the course will be trying to see how to work with nested commands or nested commands. So in most your life, sometimes they try to nest the commands under another command. So let's see how to work with it right. So an example of a simple nice command is something like this, you have the main command, then under that particular command, you have a sub command, then you have another sub command, and another sub command, we have another sub command, right? So this is going to be like the period and then this is going to be listed a child, then these are going to be another Dc grandchild, right?

Is something very simple. It's very easy. So how do you create a nested command by that too, we learnt in the previous tutorial on click on how to do that with a rebase. And now let's see how to do another one with a GPA. So I just want to create another file. I'm going to call it as nested group.

Good sila right Till I go to pay for Mr group, Alessia token is just going to input a pass, then we'll create our main function which is going to be pass the inner critic to it. Right? Very simple. Let's see how to work with it. So the simplest way that we are going to create a doc string for this our function to a simple listed command like that, right? The list initialized.

Mission is supposed to be augmented by us. good argument. Let me expand it to let you work on it. Then I'm going to give it by description to be a simple nested CLS or something like that. That is something very busy can also give the programming in case you want to specify the name that you want to give for the program. So let's call it us, this did something very simple.

Okay, because that is something basic we have done. Now let's see how to work on a subcommittee. So the first one is we are going to create a main parser so this is going to be our main parser so we're just going to initialize by going to be our main parser right, then we're to create a sub parser so the sub path is going to be used as the sub command so it's going to be our sub parser pool sub command. To disable this sub password has to be using to list it up so I'm just going to be sub pasa can be passed can be passing anyhow you want it to be good to go. But add some passes. Just because b sub passes pivot, then I just go with a little just a mean command or something like that.

Whoa, let's go to the sub sub command. Very simple, and is what we need, right our sub commands, we have need to create a simple sub parser and emit parser. Now to be able to do another command under that school, it is going to be a sub command. Let's call this list parser. to list out something, they're going to be using a sub party that you created. So we're using the normal parser to create an argument using the sub pasa to create that, right?

There's going to be a sub process right to it, add a sub process. So if you take back from Portugal So far we have been doing let me bring it reticle. See whatever you do so far, it will be the one that you have been created for loops inside it. If you took whatever we do so far, it's like we call it pizza. You want to call it but I guess I get it right. But this time we are calling a pizza.

We are quitting another sub pizza, then you are going to add another pizza. Right? We are listing it again, I just go straight away with our pizza thing which we would add up but this pattern is supposed to be the big idea. So let's close this one off. Let's make it fully one. Okay, so let's continue.

So that's what you have done so far. Right? So we added that additional path and we want to call this list. Right? Then we just give it a description to help you to be on the list. All content.

So this is going to be episode we're going to do a same thing under a second. So we can have two different sub process. So this is going to be so this B list is going to be let's see, something different. This code is on us secrete pasa, right? Quito contains something like that creates a file. So if I save it now and let's come back to Oh to be x but pass a class can actually print x or nice piece we are storing everything here.

There's going to be a name space storage, right I'll call it that's a little funky with So this must be other paths, right path admit, let's try it again, I'm going to come back to Python three, or nested group that does help if I run it pivot. So now you can see from here that you have our positional argument, right? We have our sub commands, we have this list. And it's very interesting, right? So that is how to work with a nested group to just come back again. and run it for the list that has helped to give me a different scription.

So this is going to be for the list. Just like we have get maybe push origin master right calculator for this ns to know that you're trying to invest it perfectly to that. So that's the basic idea. So let's add some feature features to it to make it interesting. They need to create two passes sub commands. So we have our list and I quit, because I want to move another one under does this come back to this thing?

Added to the list just add a commit, commit. And I can actually add my argument they forgot passing by to like it can be optional arguments can be, which should not be in admin what you want to give. So let's give it a simple directory name. Liquid help, which is going to be your territory. It's probably something very easy. If I see it, let's run it again.

See how I do tree here, right basically should not commit. Very, very interesting. We still under desktop kumud. Very simple, very interesting. So we can do a lot of things with it. So that is how to add or create an asset group to the first one is just going to create your main plaza.

Then go to create a sub Plaza, we're going to be adding the various sub process. Then there's going to be a sub command over the corn. They can add argument on it, whether it's option argument or wish to not commit. So let's try with this one. Because I also want to create another is going to be like my grid but add a commit that can just go with a, let's say read only right? I just despite the fact that we could only just quit greed see creat.

Every political so they're very busy. So if I save it now and I come back here, and let's run it again. Let me find it here. I guess come back to the help. Everything is going to check with Crete agree to Crete Does that help is going to give me how to work with it to have a read only in case I want to run that particular option, let's come back to this, then go to read poorly. That's cool.

They say yes. Then just specify whatever you want to specify. Right? So great is now. Nice readable easy's very, very interesting and very simple. So that is how to work with nested group handles, we'll come back to the list option that we had, which was this list does that help.

And I can specify the directory. So let's go to this another tree so it can be any directory to see my folder, my folder. And to print out new space directory name is my food. That's how to work with ns that we can actually nest it over and over again. But the basic idea is that first of all, just create a main parser then you just go with ADD sub process, then just go with add an Add button, and the basic idea then can do anything that you want to do. So thank you for watching and see you next Session stablest

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.