Merken

Building nice command line interfaces - a look beyond the stdlib

Zitierlink des Filmsegments
Embed Code

Automatisierte Medienanalyse

Beta
Erkannte Entitäten
Sprachtranskript
if a things body and let them to my talk command-line interfaces some look around this on we perform an
important I'm back and developed by the younger converting and
consonant and this is my your Python but the 1st time this has begun and pretty excited so being able to speak you today and and what I want
to talk about our command-line interfaces and I want to show you and the on
beginning of the day um it's called brewery and I sort I'm originally from the various sort german guy from related to something with ya and this is a typical extremal I think everyone you know so what the common line interface and so that's that's going as so this year usage slime uh you therefore for the description used you have some options and of course some set commands moment yeah can call of commands you separated at pages for supplements this would look like this the going to be helpful this kind can you can see the by able to list some of BS slowed to switch long I just OK so you then it is it is actually uh attributes from the Augustine abroad the famous Peruvian from know time and we can also the we have seen we have some other options you can all the years don't have and you and all but we can bias receptivity India of this a list of what buy command look like so you have an option name and the 1st 2 columns the only thing that you the and that's what it's it's very clear from so now we have 6 points of the year so just that's just a short introduction so you get did you want to come differences if you don't already and what
I want to talk about this if you new to Python
programming you might wonder how to start so I was I started programming I ended up some you're passing says that are created by hand and I have seen others doing the same and so this is actually used just a list of the command-line arguments and if you tried to pass that sets you end up with pretty ugly codes and so all you the start
writing your own possible what's that are already there are already some like cannot get
doctors and implementation is the number of votes imitation plants and what its spectra from C and y and if your family of those the C programming language and if get opted might be a good fit for you but I don't recommend to you that not really nice so if you want to stick to the standard library you might find but also those more pleasant I to say what passes the red headed by an OR persist newer 1 and you have what I
think it's OK to doesn't show of it's pretty straightforward that's movement if you know if your application roles and you have a lot of of commands you always have to create all of these subclasses and yet coach starts growing not that nice so if you think so too you might be wondering if there's more and yet so I want to show you today 3 libraries which alter Click to talk about and listen the 1st 1 is clique units of project when triggered by on a hard thing a lot of fuel and all these quiet popular the communities he has traded for items last continued um and she was also not that had you what the solutions already out so he decided to write all and click was born and click this and decorate implementation so you use decorators to employ mark your functions as commands for example mn click is highly configurable and it also comes with could defaults talk court has a completely different approach and for the quot you have seen this head screens and for the popular just write to the sentence and then you will already have you pass above up to the past the stock strings and standing you get your arguments dictionaries so that certain undisclosed efforts and from a developer from OpenStack them and Cliff is small like a framework from which the level of commands something like that for example with his view that could push and so on M. and forward subcommands it uses a set of tools Andhra points so so you define an entry point in set up high and then the cliff will find its yeah I will show that later and it also comes with all but from to us in some I think I have a little demo to say that I showed you that once all let's start of click how does it look like a minimal example would look like this you just have a functioning and decorated with 2 commands degraded and yeah you're done that then you could call you scripts and you already want gets I had message looking like that which the starting point for the so you got to start writing the sad message then use that I've got function put to stop string units and get vector dictionary of 2 past arguments and options the function and this is a little bit more cold part picture it's not that complicated there are 2 important things here it's this the
class and the command manager so you have to supply us from that and then you can then you have to pass command to it and this commandment yes yeah the Commandment shows us how supplements should be formed and meant to default command miniature here environments that sup commands by a set up to 100 points like I already said so in it looks for set up there and the points in the cliff brewery to start brewery and reportedly more so
such commands for click you have not a decorator close group so notice that you're wrong message function from the
crew and then he used this group to decorate out of functions f commands as subcommands which belonged them to the school that's just these 2 lines of code and you have to 1st command so often but
it's a bit more complicated if you want to have separated help messages for each set commands because you could we could do using supplements just rides multiple usage lines you Satan instead of commands you have this body and so on and bots then you would not have separated had messages so what you can do with this you can implement you supplement and another module right you docstring there and then so check here if the command useless for example List import today Module and then put it docstring to to adopt and as using dug up to accept commands not really nice but you can see probably FIL and no class you set up prior to you have to central pawns keywords argument and knowledge say again just to stop worrying entry point groups and to find something to define a set commands you say for example this the quotes thought command switches the brewery package and then the commands module and in the commands modulus a class called you must on um which would look something like this so you just supplements from cliff command and then you will would have to overload take action function take action function um already gets and passed the past arguments as argument and these are in our class namespace objects so and live was hot fast internally in so the next if you want to use you
probably won't use options and arguments click its again just decorated are you have the option decorated so you say we want to add that and back option to all right group and we also say it should be of flag so it's just of way value in the and and and the same for all arguments you have an extra argument degrade user the 1 which shared arguments and the system or postal passed to the this function so in talk about again
this is just writing your options and arguments and the docstring we're fortunate here if you have subcommand list which
gets this optional 3rd argument and what watching instructor message brackets and she is also an example of how such a dictionary it would look like you know what you get from the dock of the function so can go into this you would have to overload to get past a method that day you are and always have to retrieve deposit and Richardson art outside and also and then they're just used yet argument message to at different argument so here that India possible it's just some change another feature perhaps you don't want all want optional arguments that you want repeating arguments in click you can could achieve keyword argument and arts and arts and the argument the cradle so if you use minus 1 for example this means you can put an infinite number of food arguments to command and federal would then be the tuple of strings smart just the string and then up again trust documenting it's
still some so in such a help screen repeating his ideas ellipses history points and the filter and deoxy dictionary and what's he list they are classed as also in an ox keyword argument about here it's not a minus 1 if it's an asterisk and that's all of them so another thing
on defaults so you don't want to special specify a value to every option all the time so for example if you fall by command we could say if we don't specify a number of what you want to buy and just by 1 so this is dominantly by the addition of white by the default keyword argument and you also have required argument if you really want to say this option should be given a specified In the you
have to parents and this is the forward ones to achieve tree and often option had strings and the same for a wild and you know that's all basically for class
again it's the same way for click just to require can't afford arguments and accurate arguments 1 difference here was that click use the and if you specify default value click uses the type of W have T for as that time
so if you would use common to have something as an integer you would get a picture would raise an error and so what you
but we also want to use type support to validate your arguments and options also solely in to you have the type an argument and click also has nice utilities for example custom types here I used an entrenched has type because buying 0
or less forms would be nonsense anyway so said that should be between one and infinity but what does not have
any times it's just everything
is a string of blue and you have to do the checking itself on for hot gasses you also have this type keyword argument sweating basically the same like and click in OK so now feature
if you want to automate things for example you might want to use environment variables and In click again it's just another keyword arguments so you specify and floor and in the example you can see I if you don't have to spend following set already it could default value would use but if you set descend from the indian flow is used and talk about again does not have the support for environment variables and also Hough past us not have it part but you can do this trick
so you just set the default value and use the environs dictionary elements then you have basically the same effect like and click small you probably also want to test this stuff if it's you know and then click this is really nice because click comes with a of extract testing modules and in this testing what you have a key and if you will you must clear and I can trust invokes you commands and then you get back and recital object and this reside object and holds the exit code and DL approach so testing what command to terms it's really easy using other stuff like articles and so on I don't have a really good patterns so if you have 1 I would be glad if you come to me and it's not what you find in the internet this always the same you just call you functioning and and of probably a some people use the subprocess suffers as much you to call it just you script and done in the past food and so on but that just possible in world right what I did here this used high test for testing and tightest has this capsules fixture and if you use this fixture captures the output and then you can tests d or put in a similar way and this click solutions so 1 last thing booklet and
to ferrous ions I already mentioned these what would from models and clearly has special subcommands functional dismissed as just the Subcommittee subclass from command and probably show you essentially this so
this implementation you also have list commands and if you use this list class socially and then you would get this despite likely output so it's a table in the truly awful OK what you have this extra options which comes with clear you can say want to to OK the resolution is not really nice thing about you can see here you get a nice table in just by doing nothing by yourself basically what you have to
do is you have to structure the data you want to show in this table so it's just 1 had a role and then noted also want to show and yeah that's all you'll I have 1
other thing I have to this is pretty cool when using plain and so and here we can see we don't have a drink amount which is really sad so we can show this problem the goal was a single ofthis brewery drink like appliances and here we have the this entry point defined so we have few drink amount in this place and if we installed all don't yet know we have a gentleman that's so no
longer sorry my
favorite this case it's really nice working of click you have a lot of utilities that's very robust it's just fun to work with them stock Optison if you are already family of had messages and you really want to ride nights documentation and so on but of Ising for bigger applications is long that and their class I really like use hot but from what essentially it's were really easy to get an ice table what whole sorry what I have not
shown this you already that you also have multiple formant 1 fault samples you can say you want to do or what else use all it down also extensions to give chase all young and you can also specify the columns you want to show so if you just want to give names and descriptions the only yeah would just have to columns
so and all the time and
that's the end thanks for your
attention if you have questions just ask a I'll skip the coffee be thanks
be well thanks
to talk on 1 common usage in options is to have the world up to hyphen Hyphen name and the short 1 we're maybe end I I don't recall seeing any particular examples about that but I assume all these tools would support that these what so what you mean this
you will want to have some sort of what this
and the same yes sure what it used to be the 1 that was the same thing you all yeah well you can do that in history
solutions so I get great thanks that my operations I I
just cues seeing the Google plants personal everything it's called Python G floods antifuse seen what's your opinion about it you no
I think this being the death that
supports our contacts and output sorry I did supports for
commerce and output support for what gonna yeah a color only yes so right click on this this echo function I use that it's on 1 of my slides think and it's data securely something is something like a print function but it has a lot of stuff internally to handle unique codes for you on different platforms and so on and it also has a keyword arguments for colonists and get and would you would get costs and I think in popped and a clear field or are possible and have to spilled and so but I would like a tool that creates all
this competent permission from a configuration file and not to do them in the in the code in line which is the best 1 to to do that 0 maybe it's not an
option you means for doc up or look for for each of the so I don't want to write long lines of code and want to be able to let the function to the end of file and and the new they began with the story Donald it might be possible somehow but I don't think that but more questions right thing stays on top of
different good solutions for interactive command-line interface and the active and let the
kids and of the director of that so we such an example but that's
the only thing I know I don't know if something else so for click on so yeah so I actually have announced
to the and so we use click and could account of the prompting the use of it so they can actually capable of doing very very great interactive commandment process so it should be just click from them they have different options we conceptualized as such so tomorrow at quarter to 12 my talk I will talk about this you know that everything I got to question wrong but you have to say prompt a click prompt and and you get trust prompted for an option all this is that what you mean yes that a click has mn operations my Government last 1 and and in your
last projects which 1 of these 2 is did these and I present use most time
click thank about Cliff is actually quite new to me 2 and but I really like this what would form of stops so if I have a project where I could meet this and I'm just creating file although for some other data also this think it's a really good sense the OK and sink will of time for any more questions anyway we will have to go to the coffee break and I think you again Patrick
Schnittstelle
Standardabweichung
Vorlesung/Konferenz
Baum <Mathematik>
Gerade
Computeranimation
Deskriptive Statistik
Subtraktion
Punkt
Momentenproblem
Mailing-Liste
Extreme programming
Gerade
Quick-Sort
Computeranimation
Homepage
Schnittstelle
Codierung
Mailing-Liste
Optimierung
Message-Passing
Computeranimation
Programmiersprache
Abstimmung <Frequenz>
Familie <Mathematik>
Programmbibliothek
Implementierung
Zahlenbereich
Baum <Mathematik>
Fitnessfunktion
Demo <Programm>
Bit
Punkt
Klasse <Mathematik>
Implementierung
Kartesische Koordinaten
Extrempunkt
Framework <Informatik>
Computeranimation
Übergang
Datenmanagement
Einheit <Mathematik>
Maskierung <Informatik>
Vererbungshierarchie
Programmbibliothek
Skript <Programm>
Softwareentwickler
Clique <Graphentheorie>
Default
Touchscreen
Schreib-Lese-Kopf
Lineares Funktional
Parametersystem
Sichtenkonzept
Vektorraum
Data Dictionary
Filetransferprotokoll
Bildschirmmaske
Funktion <Mathematik>
Menge
Mereologie
Projektive Ebene
Programmierumgebung
Message-Passing
Zeichenkette
Metropolitan area network
Lineares Funktional
Gruppenkeim
Vorlesung/Konferenz
Gravitationsgesetz
Baum <Mathematik>
Code
Gerade
Message-Passing
Computeranimation
Zentralisator
Lucas-Zahlenreihe
Webforum
Bit
Overloading <Informatik>
Dualitätstheorie
Gerichteter Graph
Euler-Winkel
Gruppenoperation
Klasse <Mathematik>
Punktgruppe
Gruppenkeim
Extrempunkt
Computeranimation
Chatbot
Metropolitan area network
Multiplikation
Fahne <Mathematik>
Maskierung <Informatik>
Hilfesystem
Gerade
Parametersystem
Lineares Funktional
Namensraum
Gruppe <Mathematik>
Unicode
Gasströmung
Mailing-Liste
Modul
Objekt <Kategorie>
Programmfehler
Rechter Winkel
Personal Area Network
Ext-Funktor
Message-Passing
Informationssystem
Inklusion <Mathematik>
Information Retrieval
Parametersystem
Lineares Funktional
Overloading <Informatik>
Vererbungshierarchie
Mathematisierung
n-Tupel
Zahlenbereich
Mailing-Liste
Computeranimation
Unendlichkeit
Metropolitan area network
Mailing-Liste
Poisson-Klammer
Uniforme Struktur
Reelle Zahl
Ext-Funktor
Message-Passing
Informationssystem
Zeichenkette
Parametersystem
Punkt
Vererbungshierarchie
Zahlenbereich
Mailing-Liste
Zeiger <Informatik>
Computeranimation
Data Dictionary
Metropolitan area network
Default
Hilfesystem
Personal Area Network
Logik höherer Stufe
Touchscreen
Parametersystem
Subtraktion
Klasse <Mathematik>
Systemaufruf
Computeranimation
Eins
Netzwerktopologie
Metropolitan area network
Trigonometrische Funktion
Uniforme Struktur
Total <Mathematik>
Datentyp
Vererbungshierarchie
Default
Chi-Quadrat-Verteilung
Zeichenkette
Informationssystem
Data Encryption Standard
Metropolitan area network
Parametersystem
Programmfehler
Ganze Zahl
Typentheorie
Datentyp
Softwarewerkzeug
Ausgleichsrechnung
Computeranimation
Fehlermeldung
Data Encryption Standard
Metropolitan area network
Parametersystem
Bildschirmmaske
Datentyp
Typentheorie
Datentyp
Vorlesung/Konferenz
Baum <Mathematik>
Computeranimation
Unendlichkeit
Element <Mathematik>
Term
Code
Computeranimation
Internetworking
RFID
Metropolitan area network
Variable
Mustersprache
Skript <Programm>
Vorlesung/Konferenz
Default
Funktion <Mathematik>
Software Development Kit
Softwaretest
SCSI
Parametersystem
Prozessautomation
Programmierumgebung
Datenfluss
Modul
Variable
Data Dictionary
Objekt <Kategorie>
System F
Menge
Rechter Winkel
Mereologie
Programmierumgebung
Vererbungshierarchie
Klasse <Mathematik>
Implementierung
Mailing-Liste
Speicherbereichsnetzwerk
Computeranimation
Metropolitan area network
Informationsmodellierung
Mailing-Liste
Datenerfassung
Vererbungshierarchie
Bildschirmsymbol
Funktion <Mathematik>
Tabelle <Informatik>
Bildauflösung
Metropolitan area network
Service provider
Lineare Abbildung
Mailing-Liste
Punkt
Logarithmus
Binder <Informatik>
Einfache Genauigkeit
Große Vereinheitlichung
Computeranimation
Logik höherer Stufe
Tabelle <Informatik>
Klasse <Mathematik>
Familie <Mathematik>
Softwarewerkzeug
Kartesische Koordinaten
Computeranimation
Metropolitan area network
Mailing-Liste
Total <Mathematik>
Booten
Ising-Modell
Message-Passing
Tabelle <Informatik>
Informationssystem
Deskriptive Statistik
Stichprobenumfang
Maßerweiterung
Computeranimation
Vorlesung/Konferenz
Baum <Mathematik>
Computeranimation
Baum <Mathematik>
Quick-Sort
Computeranimation
Nichtlinearer Operator
Vorlesung/Konferenz
Baum <Mathematik>
Computeranimation
Rechenschieber
Parametersystem
Lineares Funktional
Datenfeld
Hochdruck
Codierung
Vorlesung/Konferenz
Kantenfärbung
Systemplattform
Baum <Mathematik>
Computeranimation
Funktion <Mathematik>
Lineares Funktional
Rechter Winkel
Schreiben <Datenverarbeitung>
Vorlesung/Konferenz
Elektronische Publikation
Konfigurationsraum
Baum <Mathematik>
Code
Gerade
Computeranimation
Subtraktion
Güte der Anpassung
Interaktives Fernsehen
Vorlesung/Konferenz
Baum <Mathematik>
Computeranimation
Nichtlinearer Operator
Prozess <Physik>
Interaktives Fernsehen
Vorlesung/Konferenz
Projektive Ebene
Baum <Mathematik>
Computeranimation
Roboter
Metropolitan area network
Red Hat
Kontrollstruktur
Vorlesung/Konferenz
Projektive Ebene
Baum <Mathematik>
Gerichteter Graph
Computeranimation

Metadaten

Formale Metadaten

Titel Building nice command line interfaces - a look beyond the stdlib
Serientitel EuroPython 2015
Teil 118
Anzahl der Teile 173
Autor Mühlbauer, Patrick
Lizenz CC-Namensnennung - keine kommerzielle Nutzung - Weitergabe unter gleichen Bedingungen 3.0 Unported:
Sie dürfen das Werk bzw. den Inhalt zu jedem legalen und nicht-kommerziellen Zweck nutzen, verändern und in unveränderter oder veränderter Form vervielfältigen, verbreiten und öffentlich zugänglich machen, sofern Sie den Namen des Autors/Rechteinhabers in der von ihm festgelegten Weise nennen und das Werk bzw. diesen Inhalt auch in veränderter Form nur unter den Bedingungen dieser Lizenz weitergeben
DOI 10.5446/20181
Herausgeber EuroPython
Erscheinungsjahr 2015
Sprache Englisch
Produktionsort Bilbao, Euskadi, Spain

Technische Metadaten

Dauer 28:58

Inhaltliche Metadaten

Fachgebiet Informatik
Abstract Patrick Mühlbauer - Building nice command line interfaces - a look beyond the stdlib One of the problems programmers are most often faced with is the parsing and validation of command-line arguments. If you're new to Python or programming in general, you might start by parsing sys.argv. Or perhaps you might've already come across standard library solutions such as getopt, optparse or argparse in the official documentation. While these modules are probably preferable to parsing sys.argv yourself, you might wonder if there are more satisfactory solutions outside of the standard library. Well, yes there are! This talk will give you an overview of some popular alternatives to the standard library solutions (e.g. click, docopt and cliff), explain their basic concepts and differences and show how you can test your CLIs.
Schlagwörter EuroPython Conference
EP 2015
EuroPython 2015

Ähnliche Filme

Loading...