SlideShare a Scribd company logo
Writing Rust CLI ApplicationsWriting Rust CLI Applications
Jean-Marcel BelmontJean-Marcel Belmont
Senior Software EngineerSenior Software Engineer
What is a cli anyway?What is a cli anyway?
“ A command-line interface or command language interpreter
(CLI), also known as command-line user interface, console user
interface[1] and character user interface (CUI), is a means of
interacting with a computer program where the user (or client)
issues commands to the program in the form of successive lines of
text (command lines). A program which handles the interface is
called a command language interpreter or shell (computing).
According to wikipedia:
clis are for hackers rightclis are for hackers right
Who needs clis I have my IDEWho needs clis I have my IDE
I press F5 and boom I am golden!!!I press F5 and boom I am golden!!!
Let the CLI Cookoff begin!!Let the CLI Cookoff begin!!
CLI program that computes a sum in Rust.CLI program that computes a sum in Rust.
Rust has several different ways to iterate through collections!
We can use a for in loop with Rust.We can use a for in loop with Rust.
Notice that we didn't put a return statement here!Notice that we didn't put a return statement here!
sum is an expression and will return.sum is an expression and will return.
We can use iterator methods to do the same actionWe can use iterator methods to do the same action
foldfold is an iterator method that applies ais an iterator method that applies a
function, producing a single, final value.function, producing a single, final value.
Notice here that we used the explicit return statement here!Notice here that we used the explicit return statement here!
Using the return statement like this is not considered idiomatic.Using the return statement like this is not considered idiomatic.
Demo!Demo!
Same summation program in Golang
CLI program that computes sum in GolangCLI program that computes sum in Golang
Here is a sum function for the Go Program
In Go you will typically use a for loop to iterate through collections.
Run sum program in go with this commandRun sum program in go with this command
Here we pass in our arguments after we run the main.go program
Alternatively you can build your program and then run the binary!
Demo!Demo!
Making an HTTP RequestMaking an HTTP Request
Let us write a Rust Script that makes an HTTP Request
Here we use the library to make an HTTP requestreqwest
Here is the main programHere is the main program
Here I put a sleep so that I could quickly copy theHere I put a sleep so that I could quickly copy the
standard output of this command!standard output of this command!
The tee command will spit out standard output andThe tee command will spit out standard output and
create a file for us in one go.create a file for us in one go.
Demo this script!!Demo this script!!
Same Program with GolangSame Program with Golang
Golang has a standard library that you can use toGolang has a standard library that you can use to
make http calls!make http calls!
No 3rd Party Libraries neededNo 3rd Party Libraries needed
You can use this handy online tool to convert jsonYou can use this handy online tool to convert json
schemas into Go Structsschemas into Go Structs
Here is the main program that makes an http requestHere is the main program that makes an http request
to Travis CI API.to Travis CI API.
Here is the rest of the programHere is the rest of the program
Notice here that I renamed the Autogenerated Name to ReposNotice here that I renamed the Autogenerated Name to Repos
Demo Time!!!Demo Time!!!
Lets Test our Rust CLILets Test our Rust CLI
programs!!programs!!
Changing the structure of the summation program for testingChanging the structure of the summation program for testing
Here we supply an option ofHere we supply an option of --lib--lib to cargo and it generates ato cargo and it generates a lib.rslib.rs
Notice that cargo generated a test for us in a file calledNotice that cargo generated a test for us in a file called lib.rslib.rs
We will break apart the 2 summation functions from the main.rs into the
lib.rs
Notice here that we add pub for public visibility
Notice here that we now use our lib as an internal crate!
We call our public method with the crate name now.
We add the following annotation to create our unit test cases.
Now we can unit test our cli program by issuing the cargo test command
Notice here that both of our unit test cases run when we run cargo test!
Demo Building average cli program!Demo Building average cli program!
Testing with GolangTesting with Golang
Let us unit test our summer cli programLet us unit test our summer cli program
We simply create a file withWe simply create a file with _test.go_test.go to writeto write
tests in Golangtests in Golang
We import the testing package into main_test.goWe import the testing package into main_test.go
Notice here that we assert numbers should not equal 12.0.Notice here that we assert numbers should not equal 12.0.
Let us run the Go Test fileLet us run the Go Test file
Hacking with the Rust clap libraryHacking with the Rust clap library
Using Clap to build Robust Clis in Rust
Clap has many features to build robust features
Using Clap to build Robust Clis in Rust
let matches = App::new("Calculator")
.subcommand(SubCommand::with_name("add")
.about("Sum some numbers")
.version("0.1")
.author("Jean-Marcel Belmont")
.arg(Arg::with_name("numbers")
.multiple(true)
.help("the numbers to add")
.required(true)))
.subcommand(SubCommand::with_name("subtract")
.about("Subtract some numbers")
.version("0.1")
.author("Jean-Marcel Belmont")
.arg(Arg::with_name("numbers")
.multiple(true)
.help("the numbers to subtract")
.index(1)
.required(true)))
Here we use subcommands to build a calculator cli application
Here we run the binary executable to run our simple
calculator cli application
Notice that each subcommand performs a different calculation.
Also notice that we are using the binary executable here.
 
It is created upon successful `cargo run` and/or `cargo build`.
DemoDemo!!!!!!
Let us look at the cobraLet us look at the cobra
No not the movie Cobra with Slyvester Stallone!No not the movie Cobra with Slyvester Stallone!
Let us look at the Golang CLI Library.Let us look at the Golang CLI Library.
Here we create a cli application with cobra init command!
We then create a symbolic link to it in this directory
Here we initialize a cobra yaml file for common info!
Now we finally create our main calculator logic.
Here is bulk of the logic for add, subtract, multiply, and divide
We have a cobra.Command and supply our function to run!
The first command runs the add subcommand.
The second command builds the binary executable.
The third command runs the binary executable and runs the
subtract subcommand.
Each command afterwards is demonstrating the other
subcommands in the calculator program.
Demo!!!Demo!!!
Let's Check off parsing, serialization, andLet's Check off parsing, serialization, and
deserialization of our Rust Bucket List Nextdeserialization of our Rust Bucket List Next
Data Serialization, Deserialization and Parsing inData Serialization, Deserialization and Parsing in
Rust CLIsRust CLIs
TheThe  crate crateserdeserde
TheThe  book bookserdeserde
We will write a command line application in Rust.
 
It will base64 decode a json web token to standard output
Use statements Library Dependencies
Here are 3 Structs and notice that the Token struct has both
the Header and Claims struct embedded in it.
The new methods for the Claims and Headers structs
instantiate a new Claims and Header instance.
Here is the main program.Here is the main program.
Demo!!!Demo!!!
Having some ascii fun now in the command line
Having some ascii fun now in the command line
This C program generates ascii characters to standard output.
./ascii_table | sed "s;.;'&',;g" | pbcopy
This shell command replaces the output with double quotes and a
comma and copies standard output to system clipboard
The main rust program just prints some ascii characters to
standard output for fun!!
Time to shred some web scraping waves!!Time to shred some web scraping waves!!
Here are our dependencies for the Web Scraping project:
Here is our use and crate statements:
Here is the main logic for the Web Scraping Project
Here is the main function:
Notice that we ran the run() function and wrap it in a `if let`
statement which will print error and exit if there is an error.
Demo!!Demo!!
Debugging Rust ApplicationsDebugging Rust Applications
Printing values with println! macro in RustPrinting values with println! macro in Rust
Printing with named value
Pretty Print with println("{:#?}", something);
Debugging Rust applications with rust-lldb.
There are 2 debuggers that come prebundled with cargo:
rust-lldb
rust-gdb
If you are working on Mac OS X it is easier to use rust-lldb
You can use gdb in Mac OS X but it requires extra steps:
First install gdb, easiest way is via homebrew package manager
Next you will need to codesign gdb, if you are interested follow
the steps in this CODESIGN-GIST
For the purposes of this demo we will use rust-lldb
Here we start rust-lldb using the compiled binary executable
Notice here that we run the main.rs file by issuing the command run
Let us set a breakpoint in lldb
This is the short form version of setting a breakpoint
This is the longer but more powerful way to set breakpoint
Let us run our program with breakpoint set
Notice here that lldb stopped in line 6 which is our breakpoint!
We issued command "frame variable args" to see variable
Note that the commands for printing: p (simple types), po
(objects), and pa (arrays) don't work as well with Rust.
The frame command is used to examine current stack frame and
has various subcommands such as variable which work better!
Step over with lldb
Resume/Continue execution of program
Notice here that we continued until the next breakpoint!
List breakpoints
Delete all breakpoints
Delete specific breakpoint(s)
First do Instruction level single step, stepping over calls
Next actually step into function
Next let us step over and then print value of variable
Step out of the function
Get stack frame information and continue execution
Use expression to set values in running program
Print back trace information
Kill lldb session
Questions?Questions?
How to find me:How to find me:
@ Github@ Githubjbelmontjbelmont
@ Twitter@ Twitterjbelmont80jbelmont80
Personal website @Personal website @ marcelbelmont.commarcelbelmont.com
@ LinkedIn@ LinkedInJean-Marcel BelmontJean-Marcel Belmont
Checkout my new book titled Hands On Continuous
Integration with Jenkins, Travis, and Circle CI

More Related Content

What's hot

KubeCon EU 2016: Leveraging ephemeral namespaces in a CI/CD pipeline
KubeCon EU 2016: Leveraging ephemeral namespaces in a CI/CD pipelineKubeCon EU 2016: Leveraging ephemeral namespaces in a CI/CD pipeline
KubeCon EU 2016: Leveraging ephemeral namespaces in a CI/CD pipeline
KubeAcademy
 
Where is my scalable API?
Where is my scalable API?Where is my scalable API?
Where is my scalable API?
Juan Pablo Genovese
 
Vagrant - the essence of DevOps in a tool
Vagrant - the essence of DevOps in a toolVagrant - the essence of DevOps in a tool
Vagrant - the essence of DevOps in a tool
Paul Stack
 
KubeCon EU 2016: Getting the Jobs Done With Kubernetes
KubeCon EU 2016: Getting the Jobs Done With KubernetesKubeCon EU 2016: Getting the Jobs Done With Kubernetes
KubeCon EU 2016: Getting the Jobs Done With Kubernetes
KubeAcademy
 
Dev ops with smell v1.2
Dev ops with smell v1.2Dev ops with smell v1.2
Dev ops with smell v1.2
Antons Kranga
 
An Introduction to Rancher
An Introduction to RancherAn Introduction to Rancher
An Introduction to Rancher
Conner Swann
 
Monitoring kubernetes with prometheus
Monitoring kubernetes with prometheusMonitoring kubernetes with prometheus
Monitoring kubernetes with prometheus
Brice Fernandes
 
Serverless, Tekton, and Argo CD: How to craft modern CI/CD workflows | DevNat...
Serverless, Tekton, and Argo CD: How to craft modern CI/CD workflows | DevNat...Serverless, Tekton, and Argo CD: How to craft modern CI/CD workflows | DevNat...
Serverless, Tekton, and Argo CD: How to craft modern CI/CD workflows | DevNat...
Red Hat Developers
 
Making Spinnaker Go @ Stitch Fix
Making Spinnaker Go @ Stitch FixMaking Spinnaker Go @ Stitch Fix
Making Spinnaker Go @ Stitch Fix
Diana Tkachenko
 
Microservices: 5 things I wish I'd known - Vincent Kok - Codemotion Amsterdam...
Microservices: 5 things I wish I'd known - Vincent Kok - Codemotion Amsterdam...Microservices: 5 things I wish I'd known - Vincent Kok - Codemotion Amsterdam...
Microservices: 5 things I wish I'd known - Vincent Kok - Codemotion Amsterdam...
Codemotion
 
Airflow Clustering and High Availability
Airflow Clustering and High AvailabilityAirflow Clustering and High Availability
Airflow Clustering and High Availability
Robert Sanders
 
DevOps Summit 2016 - The immutable Journey
DevOps Summit 2016 - The immutable JourneyDevOps Summit 2016 - The immutable Journey
DevOps Summit 2016 - The immutable Journey
smalltown
 
Automated testing on steroids – Trick for managing test data using Docker sna...
Automated testing on steroids – Trick for managing test data using Docker sna...Automated testing on steroids – Trick for managing test data using Docker sna...
Automated testing on steroids – Trick for managing test data using Docker sna...
Lucas Jellema
 
Simon Laws – Apache Flink Cluster Deployment on Docker and Docker-Compose
Simon Laws – Apache Flink Cluster Deployment on Docker and Docker-ComposeSimon Laws – Apache Flink Cluster Deployment on Docker and Docker-Compose
Simon Laws – Apache Flink Cluster Deployment on Docker and Docker-Compose
Flink Forward
 
Integration testing for salt states using aws ec2 container service
Integration testing for salt states using aws ec2 container serviceIntegration testing for salt states using aws ec2 container service
Integration testing for salt states using aws ec2 container service
SaltStack
 
Gitlab and Lingvokot
Gitlab and LingvokotGitlab and Lingvokot
Gitlab and Lingvokot
Lingvokot
 
From Arm to Z: Building, Shipping, and Running a Multi-platform Docker Swarm ...
From Arm to Z: Building, Shipping, and Running a Multi-platform Docker Swarm ...From Arm to Z: Building, Shipping, and Running a Multi-platform Docker Swarm ...
From Arm to Z: Building, Shipping, and Running a Multi-platform Docker Swarm ...
Docker, Inc.
 
Securing Containers, One Patch at a Time - Michael Crosby, Docker
Securing Containers, One Patch at a Time - Michael Crosby, DockerSecuring Containers, One Patch at a Time - Michael Crosby, Docker
Securing Containers, One Patch at a Time - Michael Crosby, Docker
Docker, Inc.
 
Performance Tuning Your Puppet Infrastructure - PuppetConf 2014
Performance Tuning Your Puppet Infrastructure - PuppetConf 2014Performance Tuning Your Puppet Infrastructure - PuppetConf 2014
Performance Tuning Your Puppet Infrastructure - PuppetConf 2014
Puppet
 
Automate CI/CD with Rancher
Automate CI/CD with RancherAutomate CI/CD with Rancher
Automate CI/CD with Rancher
Nick Thomas
 

What's hot (20)

KubeCon EU 2016: Leveraging ephemeral namespaces in a CI/CD pipeline
KubeCon EU 2016: Leveraging ephemeral namespaces in a CI/CD pipelineKubeCon EU 2016: Leveraging ephemeral namespaces in a CI/CD pipeline
KubeCon EU 2016: Leveraging ephemeral namespaces in a CI/CD pipeline
 
Where is my scalable API?
Where is my scalable API?Where is my scalable API?
Where is my scalable API?
 
Vagrant - the essence of DevOps in a tool
Vagrant - the essence of DevOps in a toolVagrant - the essence of DevOps in a tool
Vagrant - the essence of DevOps in a tool
 
KubeCon EU 2016: Getting the Jobs Done With Kubernetes
KubeCon EU 2016: Getting the Jobs Done With KubernetesKubeCon EU 2016: Getting the Jobs Done With Kubernetes
KubeCon EU 2016: Getting the Jobs Done With Kubernetes
 
Dev ops with smell v1.2
Dev ops with smell v1.2Dev ops with smell v1.2
Dev ops with smell v1.2
 
An Introduction to Rancher
An Introduction to RancherAn Introduction to Rancher
An Introduction to Rancher
 
Monitoring kubernetes with prometheus
Monitoring kubernetes with prometheusMonitoring kubernetes with prometheus
Monitoring kubernetes with prometheus
 
Serverless, Tekton, and Argo CD: How to craft modern CI/CD workflows | DevNat...
Serverless, Tekton, and Argo CD: How to craft modern CI/CD workflows | DevNat...Serverless, Tekton, and Argo CD: How to craft modern CI/CD workflows | DevNat...
Serverless, Tekton, and Argo CD: How to craft modern CI/CD workflows | DevNat...
 
Making Spinnaker Go @ Stitch Fix
Making Spinnaker Go @ Stitch FixMaking Spinnaker Go @ Stitch Fix
Making Spinnaker Go @ Stitch Fix
 
Microservices: 5 things I wish I'd known - Vincent Kok - Codemotion Amsterdam...
Microservices: 5 things I wish I'd known - Vincent Kok - Codemotion Amsterdam...Microservices: 5 things I wish I'd known - Vincent Kok - Codemotion Amsterdam...
Microservices: 5 things I wish I'd known - Vincent Kok - Codemotion Amsterdam...
 
Airflow Clustering and High Availability
Airflow Clustering and High AvailabilityAirflow Clustering and High Availability
Airflow Clustering and High Availability
 
DevOps Summit 2016 - The immutable Journey
DevOps Summit 2016 - The immutable JourneyDevOps Summit 2016 - The immutable Journey
DevOps Summit 2016 - The immutable Journey
 
Automated testing on steroids – Trick for managing test data using Docker sna...
Automated testing on steroids – Trick for managing test data using Docker sna...Automated testing on steroids – Trick for managing test data using Docker sna...
Automated testing on steroids – Trick for managing test data using Docker sna...
 
Simon Laws – Apache Flink Cluster Deployment on Docker and Docker-Compose
Simon Laws – Apache Flink Cluster Deployment on Docker and Docker-ComposeSimon Laws – Apache Flink Cluster Deployment on Docker and Docker-Compose
Simon Laws – Apache Flink Cluster Deployment on Docker and Docker-Compose
 
Integration testing for salt states using aws ec2 container service
Integration testing for salt states using aws ec2 container serviceIntegration testing for salt states using aws ec2 container service
Integration testing for salt states using aws ec2 container service
 
Gitlab and Lingvokot
Gitlab and LingvokotGitlab and Lingvokot
Gitlab and Lingvokot
 
From Arm to Z: Building, Shipping, and Running a Multi-platform Docker Swarm ...
From Arm to Z: Building, Shipping, and Running a Multi-platform Docker Swarm ...From Arm to Z: Building, Shipping, and Running a Multi-platform Docker Swarm ...
From Arm to Z: Building, Shipping, and Running a Multi-platform Docker Swarm ...
 
Securing Containers, One Patch at a Time - Michael Crosby, Docker
Securing Containers, One Patch at a Time - Michael Crosby, DockerSecuring Containers, One Patch at a Time - Michael Crosby, Docker
Securing Containers, One Patch at a Time - Michael Crosby, Docker
 
Performance Tuning Your Puppet Infrastructure - PuppetConf 2014
Performance Tuning Your Puppet Infrastructure - PuppetConf 2014Performance Tuning Your Puppet Infrastructure - PuppetConf 2014
Performance Tuning Your Puppet Infrastructure - PuppetConf 2014
 
Automate CI/CD with Rancher
Automate CI/CD with RancherAutomate CI/CD with Rancher
Automate CI/CD with Rancher
 

Similar to Writing Rust Command Line Applications

Scripting Embulk Plugins
Scripting Embulk PluginsScripting Embulk Plugins
Scripting Embulk Plugins
Sadayuki Furuhashi
 
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides:  Let's build macOS CLI Utilities using SwiftMobileConf 2021 Slides:  Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
Diego Freniche Brito
 
Lambda lambda-lambda
Lambda lambda-lambdaLambda lambda-lambda
Lambda lambda-lambda
Chris Mitchell
 
Kubernetes - State of the Union (Q1-2016)
Kubernetes - State of the Union (Q1-2016)Kubernetes - State of the Union (Q1-2016)
Kubernetes - State of the Union (Q1-2016)
DoiT International
 
TestUpload
TestUploadTestUpload
TestUpload
ZarksaDS
 
Mac ruby deployment
Mac ruby deploymentMac ruby deployment
Mac ruby deployment
Thilo Utke
 
Serverless in production, an experience report (CoDe-Conf)
Serverless in production, an experience report (CoDe-Conf)Serverless in production, an experience report (CoDe-Conf)
Serverless in production, an experience report (CoDe-Conf)
Yan Cui
 
AWS Lambda from the trenches
AWS Lambda from the trenchesAWS Lambda from the trenches
AWS Lambda from the trenches
Yan Cui
 
Attacking Pipelines--Security meets Continuous Delivery
Attacking Pipelines--Security meets Continuous DeliveryAttacking Pipelines--Security meets Continuous Delivery
Attacking Pipelines--Security meets Continuous Delivery
James Wickett
 
ContainerDays Boston 2015: "Continuous Delivery with Containers" (Nick Gauthier)
ContainerDays Boston 2015: "Continuous Delivery with Containers" (Nick Gauthier)ContainerDays Boston 2015: "Continuous Delivery with Containers" (Nick Gauthier)
ContainerDays Boston 2015: "Continuous Delivery with Containers" (Nick Gauthier)
DynamicInfraDays
 
Raising the Bar on Robotics Code Quality
Raising the Bar on Robotics Code QualityRaising the Bar on Robotics Code Quality
Raising the Bar on Robotics Code Quality
Thomas Moulard
 
Introduction to Programming Lesson 01
Introduction to Programming Lesson 01Introduction to Programming Lesson 01
Introduction to Programming Lesson 01
A-Tech and Software Development
 
A Fabric/Puppet Build/Deploy System
A Fabric/Puppet Build/Deploy SystemA Fabric/Puppet Build/Deploy System
A Fabric/Puppet Build/Deploy System
adrian_nye
 
Ransack, an Application Built on Ansible's API for Rackspace -- AnsibleFest N...
Ransack, an Application Built on Ansible's API for Rackspace -- AnsibleFest N...Ransack, an Application Built on Ansible's API for Rackspace -- AnsibleFest N...
Ransack, an Application Built on Ansible's API for Rackspace -- AnsibleFest N...
Paul Durivage
 
DevOps(4) : Ansible(2) - (MOSG)
DevOps(4) : Ansible(2) - (MOSG)DevOps(4) : Ansible(2) - (MOSG)
DevOps(4) : Ansible(2) - (MOSG)
Soshi Nemoto
 
Pilot Tech Talk #10 — Practical automation by Kamil Cholewiński
Pilot Tech Talk #10 — Practical automation by Kamil CholewińskiPilot Tech Talk #10 — Practical automation by Kamil Cholewiński
Pilot Tech Talk #10 — Practical automation by Kamil Cholewiński
Pilot
 
01 Introduction to programming
01 Introduction to programming01 Introduction to programming
01 Introduction to programming
maznabili
 
TypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack DevelopersTypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack Developers
Rutenis Turcinas
 
Agile JavaScript Testing
Agile JavaScript TestingAgile JavaScript Testing
Agile JavaScript Testing
Scott Becker
 
Rspec
RspecRspec

Similar to Writing Rust Command Line Applications (20)

Scripting Embulk Plugins
Scripting Embulk PluginsScripting Embulk Plugins
Scripting Embulk Plugins
 
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides:  Let's build macOS CLI Utilities using SwiftMobileConf 2021 Slides:  Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
 
Lambda lambda-lambda
Lambda lambda-lambdaLambda lambda-lambda
Lambda lambda-lambda
 
Kubernetes - State of the Union (Q1-2016)
Kubernetes - State of the Union (Q1-2016)Kubernetes - State of the Union (Q1-2016)
Kubernetes - State of the Union (Q1-2016)
 
TestUpload
TestUploadTestUpload
TestUpload
 
Mac ruby deployment
Mac ruby deploymentMac ruby deployment
Mac ruby deployment
 
Serverless in production, an experience report (CoDe-Conf)
Serverless in production, an experience report (CoDe-Conf)Serverless in production, an experience report (CoDe-Conf)
Serverless in production, an experience report (CoDe-Conf)
 
AWS Lambda from the trenches
AWS Lambda from the trenchesAWS Lambda from the trenches
AWS Lambda from the trenches
 
Attacking Pipelines--Security meets Continuous Delivery
Attacking Pipelines--Security meets Continuous DeliveryAttacking Pipelines--Security meets Continuous Delivery
Attacking Pipelines--Security meets Continuous Delivery
 
ContainerDays Boston 2015: "Continuous Delivery with Containers" (Nick Gauthier)
ContainerDays Boston 2015: "Continuous Delivery with Containers" (Nick Gauthier)ContainerDays Boston 2015: "Continuous Delivery with Containers" (Nick Gauthier)
ContainerDays Boston 2015: "Continuous Delivery with Containers" (Nick Gauthier)
 
Raising the Bar on Robotics Code Quality
Raising the Bar on Robotics Code QualityRaising the Bar on Robotics Code Quality
Raising the Bar on Robotics Code Quality
 
Introduction to Programming Lesson 01
Introduction to Programming Lesson 01Introduction to Programming Lesson 01
Introduction to Programming Lesson 01
 
A Fabric/Puppet Build/Deploy System
A Fabric/Puppet Build/Deploy SystemA Fabric/Puppet Build/Deploy System
A Fabric/Puppet Build/Deploy System
 
Ransack, an Application Built on Ansible's API for Rackspace -- AnsibleFest N...
Ransack, an Application Built on Ansible's API for Rackspace -- AnsibleFest N...Ransack, an Application Built on Ansible's API for Rackspace -- AnsibleFest N...
Ransack, an Application Built on Ansible's API for Rackspace -- AnsibleFest N...
 
DevOps(4) : Ansible(2) - (MOSG)
DevOps(4) : Ansible(2) - (MOSG)DevOps(4) : Ansible(2) - (MOSG)
DevOps(4) : Ansible(2) - (MOSG)
 
Pilot Tech Talk #10 — Practical automation by Kamil Cholewiński
Pilot Tech Talk #10 — Practical automation by Kamil CholewińskiPilot Tech Talk #10 — Practical automation by Kamil Cholewiński
Pilot Tech Talk #10 — Practical automation by Kamil Cholewiński
 
01 Introduction to programming
01 Introduction to programming01 Introduction to programming
01 Introduction to programming
 
TypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack DevelopersTypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack Developers
 
Agile JavaScript Testing
Agile JavaScript TestingAgile JavaScript Testing
Agile JavaScript Testing
 
Rspec
RspecRspec
Rspec
 

More from All Things Open

Building Reliability - The Realities of Observability
Building Reliability - The Realities of ObservabilityBuilding Reliability - The Realities of Observability
Building Reliability - The Realities of Observability
All Things Open
 
Modern Database Best Practices
Modern Database Best PracticesModern Database Best Practices
Modern Database Best Practices
All Things Open
 
Open Source and Public Policy
Open Source and Public PolicyOpen Source and Public Policy
Open Source and Public Policy
All Things Open
 
Weaving Microservices into a Unified GraphQL Schema with graph-quilt - Ashpak...
Weaving Microservices into a Unified GraphQL Schema with graph-quilt - Ashpak...Weaving Microservices into a Unified GraphQL Schema with graph-quilt - Ashpak...
Weaving Microservices into a Unified GraphQL Schema with graph-quilt - Ashpak...
All Things Open
 
The State of Passwordless Auth on the Web - Phil Nash
The State of Passwordless Auth on the Web - Phil NashThe State of Passwordless Auth on the Web - Phil Nash
The State of Passwordless Auth on the Web - Phil Nash
All Things Open
 
Total ReDoS: The dangers of regex in JavaScript
Total ReDoS: The dangers of regex in JavaScriptTotal ReDoS: The dangers of regex in JavaScript
Total ReDoS: The dangers of regex in JavaScript
All Things Open
 
What Does Real World Mass Adoption of Decentralized Tech Look Like?
What Does Real World Mass Adoption of Decentralized Tech Look Like?What Does Real World Mass Adoption of Decentralized Tech Look Like?
What Does Real World Mass Adoption of Decentralized Tech Look Like?
All Things Open
 
How to Write & Deploy a Smart Contract
How to Write & Deploy a Smart ContractHow to Write & Deploy a Smart Contract
How to Write & Deploy a Smart Contract
All Things Open
 
Spinning Your Drones with Cadence Workflows, Apache Kafka and TensorFlow
 Spinning Your Drones with Cadence Workflows, Apache Kafka and TensorFlow Spinning Your Drones with Cadence Workflows, Apache Kafka and TensorFlow
Spinning Your Drones with Cadence Workflows, Apache Kafka and TensorFlow
All Things Open
 
DEI Challenges and Success
DEI Challenges and SuccessDEI Challenges and Success
DEI Challenges and Success
All Things Open
 
Scaling Web Applications with Background
Scaling Web Applications with BackgroundScaling Web Applications with Background
Scaling Web Applications with Background
All Things Open
 
Supercharging tutorials with WebAssembly
Supercharging tutorials with WebAssemblySupercharging tutorials with WebAssembly
Supercharging tutorials with WebAssembly
All Things Open
 
Using SQL to Find Needles in Haystacks
Using SQL to Find Needles in HaystacksUsing SQL to Find Needles in Haystacks
Using SQL to Find Needles in Haystacks
All Things Open
 
Configuration Security as a Game of Pursuit Intercept
Configuration Security as a Game of Pursuit InterceptConfiguration Security as a Game of Pursuit Intercept
Configuration Security as a Game of Pursuit Intercept
All Things Open
 
Scaling an Open Source Sponsorship Program
Scaling an Open Source Sponsorship ProgramScaling an Open Source Sponsorship Program
Scaling an Open Source Sponsorship Program
All Things Open
 
Build Developer Experience Teams for Open Source
Build Developer Experience Teams for Open SourceBuild Developer Experience Teams for Open Source
Build Developer Experience Teams for Open Source
All Things Open
 
Deploying Models at Scale with Apache Beam
Deploying Models at Scale with Apache BeamDeploying Models at Scale with Apache Beam
Deploying Models at Scale with Apache Beam
All Things Open
 
Sudo – Giving access while staying in control
Sudo – Giving access while staying in controlSudo – Giving access while staying in control
Sudo – Giving access while staying in control
All Things Open
 
Fortifying the Future: Tackling Security Challenges in AI/ML Applications
Fortifying the Future: Tackling Security Challenges in AI/ML ApplicationsFortifying the Future: Tackling Security Challenges in AI/ML Applications
Fortifying the Future: Tackling Security Challenges in AI/ML Applications
All Things Open
 
Securing Cloud Resources Deployed with Control Planes on Kubernetes using Gov...
Securing Cloud Resources Deployed with Control Planes on Kubernetes using Gov...Securing Cloud Resources Deployed with Control Planes on Kubernetes using Gov...
Securing Cloud Resources Deployed with Control Planes on Kubernetes using Gov...
All Things Open
 

More from All Things Open (20)

Building Reliability - The Realities of Observability
Building Reliability - The Realities of ObservabilityBuilding Reliability - The Realities of Observability
Building Reliability - The Realities of Observability
 
Modern Database Best Practices
Modern Database Best PracticesModern Database Best Practices
Modern Database Best Practices
 
Open Source and Public Policy
Open Source and Public PolicyOpen Source and Public Policy
Open Source and Public Policy
 
Weaving Microservices into a Unified GraphQL Schema with graph-quilt - Ashpak...
Weaving Microservices into a Unified GraphQL Schema with graph-quilt - Ashpak...Weaving Microservices into a Unified GraphQL Schema with graph-quilt - Ashpak...
Weaving Microservices into a Unified GraphQL Schema with graph-quilt - Ashpak...
 
The State of Passwordless Auth on the Web - Phil Nash
The State of Passwordless Auth on the Web - Phil NashThe State of Passwordless Auth on the Web - Phil Nash
The State of Passwordless Auth on the Web - Phil Nash
 
Total ReDoS: The dangers of regex in JavaScript
Total ReDoS: The dangers of regex in JavaScriptTotal ReDoS: The dangers of regex in JavaScript
Total ReDoS: The dangers of regex in JavaScript
 
What Does Real World Mass Adoption of Decentralized Tech Look Like?
What Does Real World Mass Adoption of Decentralized Tech Look Like?What Does Real World Mass Adoption of Decentralized Tech Look Like?
What Does Real World Mass Adoption of Decentralized Tech Look Like?
 
How to Write & Deploy a Smart Contract
How to Write & Deploy a Smart ContractHow to Write & Deploy a Smart Contract
How to Write & Deploy a Smart Contract
 
Spinning Your Drones with Cadence Workflows, Apache Kafka and TensorFlow
 Spinning Your Drones with Cadence Workflows, Apache Kafka and TensorFlow Spinning Your Drones with Cadence Workflows, Apache Kafka and TensorFlow
Spinning Your Drones with Cadence Workflows, Apache Kafka and TensorFlow
 
DEI Challenges and Success
DEI Challenges and SuccessDEI Challenges and Success
DEI Challenges and Success
 
Scaling Web Applications with Background
Scaling Web Applications with BackgroundScaling Web Applications with Background
Scaling Web Applications with Background
 
Supercharging tutorials with WebAssembly
Supercharging tutorials with WebAssemblySupercharging tutorials with WebAssembly
Supercharging tutorials with WebAssembly
 
Using SQL to Find Needles in Haystacks
Using SQL to Find Needles in HaystacksUsing SQL to Find Needles in Haystacks
Using SQL to Find Needles in Haystacks
 
Configuration Security as a Game of Pursuit Intercept
Configuration Security as a Game of Pursuit InterceptConfiguration Security as a Game of Pursuit Intercept
Configuration Security as a Game of Pursuit Intercept
 
Scaling an Open Source Sponsorship Program
Scaling an Open Source Sponsorship ProgramScaling an Open Source Sponsorship Program
Scaling an Open Source Sponsorship Program
 
Build Developer Experience Teams for Open Source
Build Developer Experience Teams for Open SourceBuild Developer Experience Teams for Open Source
Build Developer Experience Teams for Open Source
 
Deploying Models at Scale with Apache Beam
Deploying Models at Scale with Apache BeamDeploying Models at Scale with Apache Beam
Deploying Models at Scale with Apache Beam
 
Sudo – Giving access while staying in control
Sudo – Giving access while staying in controlSudo – Giving access while staying in control
Sudo – Giving access while staying in control
 
Fortifying the Future: Tackling Security Challenges in AI/ML Applications
Fortifying the Future: Tackling Security Challenges in AI/ML ApplicationsFortifying the Future: Tackling Security Challenges in AI/ML Applications
Fortifying the Future: Tackling Security Challenges in AI/ML Applications
 
Securing Cloud Resources Deployed with Control Planes on Kubernetes using Gov...
Securing Cloud Resources Deployed with Control Planes on Kubernetes using Gov...Securing Cloud Resources Deployed with Control Planes on Kubernetes using Gov...
Securing Cloud Resources Deployed with Control Planes on Kubernetes using Gov...
 

Recently uploaded

Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Wask
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 

Recently uploaded (20)

Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 

Writing Rust Command Line Applications

  • 1. Writing Rust CLI ApplicationsWriting Rust CLI Applications Jean-Marcel BelmontJean-Marcel Belmont Senior Software EngineerSenior Software Engineer
  • 2. What is a cli anyway?What is a cli anyway? “ A command-line interface or command language interpreter (CLI), also known as command-line user interface, console user interface[1] and character user interface (CUI), is a means of interacting with a computer program where the user (or client) issues commands to the program in the form of successive lines of text (command lines). A program which handles the interface is called a command language interpreter or shell (computing). According to wikipedia:
  • 3. clis are for hackers rightclis are for hackers right
  • 4. Who needs clis I have my IDEWho needs clis I have my IDE I press F5 and boom I am golden!!!I press F5 and boom I am golden!!!
  • 5. Let the CLI Cookoff begin!!Let the CLI Cookoff begin!!
  • 6. CLI program that computes a sum in Rust.CLI program that computes a sum in Rust. Rust has several different ways to iterate through collections!
  • 7. We can use a for in loop with Rust.We can use a for in loop with Rust. Notice that we didn't put a return statement here!Notice that we didn't put a return statement here! sum is an expression and will return.sum is an expression and will return.
  • 8. We can use iterator methods to do the same actionWe can use iterator methods to do the same action foldfold is an iterator method that applies ais an iterator method that applies a function, producing a single, final value.function, producing a single, final value. Notice here that we used the explicit return statement here!Notice here that we used the explicit return statement here! Using the return statement like this is not considered idiomatic.Using the return statement like this is not considered idiomatic.
  • 11. CLI program that computes sum in GolangCLI program that computes sum in Golang
  • 12. Here is a sum function for the Go Program In Go you will typically use a for loop to iterate through collections.
  • 13. Run sum program in go with this commandRun sum program in go with this command Here we pass in our arguments after we run the main.go program Alternatively you can build your program and then run the binary!
  • 15. Making an HTTP RequestMaking an HTTP Request
  • 16. Let us write a Rust Script that makes an HTTP Request Here we use the library to make an HTTP requestreqwest
  • 17. Here is the main programHere is the main program
  • 18. Here I put a sleep so that I could quickly copy theHere I put a sleep so that I could quickly copy the standard output of this command!standard output of this command! The tee command will spit out standard output andThe tee command will spit out standard output and create a file for us in one go.create a file for us in one go.
  • 19. Demo this script!!Demo this script!!
  • 20. Same Program with GolangSame Program with Golang
  • 21. Golang has a standard library that you can use toGolang has a standard library that you can use to make http calls!make http calls! No 3rd Party Libraries neededNo 3rd Party Libraries needed
  • 22. You can use this handy online tool to convert jsonYou can use this handy online tool to convert json schemas into Go Structsschemas into Go Structs
  • 23. Here is the main program that makes an http requestHere is the main program that makes an http request to Travis CI API.to Travis CI API.
  • 24. Here is the rest of the programHere is the rest of the program Notice here that I renamed the Autogenerated Name to ReposNotice here that I renamed the Autogenerated Name to Repos
  • 26. Lets Test our Rust CLILets Test our Rust CLI programs!!programs!!
  • 27. Changing the structure of the summation program for testingChanging the structure of the summation program for testing Here we supply an option ofHere we supply an option of --lib--lib to cargo and it generates ato cargo and it generates a lib.rslib.rs Notice that cargo generated a test for us in a file calledNotice that cargo generated a test for us in a file called lib.rslib.rs
  • 28. We will break apart the 2 summation functions from the main.rs into the lib.rs Notice here that we add pub for public visibility
  • 29. Notice here that we now use our lib as an internal crate! We call our public method with the crate name now.
  • 30. We add the following annotation to create our unit test cases.
  • 31. Now we can unit test our cli program by issuing the cargo test command Notice here that both of our unit test cases run when we run cargo test!
  • 32. Demo Building average cli program!Demo Building average cli program!
  • 34. Let us unit test our summer cli programLet us unit test our summer cli program We simply create a file withWe simply create a file with _test.go_test.go to writeto write tests in Golangtests in Golang
  • 35. We import the testing package into main_test.goWe import the testing package into main_test.go Notice here that we assert numbers should not equal 12.0.Notice here that we assert numbers should not equal 12.0.
  • 36. Let us run the Go Test fileLet us run the Go Test file
  • 37. Hacking with the Rust clap libraryHacking with the Rust clap library
  • 38. Using Clap to build Robust Clis in Rust Clap has many features to build robust features
  • 39. Using Clap to build Robust Clis in Rust let matches = App::new("Calculator") .subcommand(SubCommand::with_name("add") .about("Sum some numbers") .version("0.1") .author("Jean-Marcel Belmont") .arg(Arg::with_name("numbers") .multiple(true) .help("the numbers to add") .required(true))) .subcommand(SubCommand::with_name("subtract") .about("Subtract some numbers") .version("0.1") .author("Jean-Marcel Belmont") .arg(Arg::with_name("numbers") .multiple(true) .help("the numbers to subtract") .index(1) .required(true))) Here we use subcommands to build a calculator cli application
  • 40. Here we run the binary executable to run our simple calculator cli application Notice that each subcommand performs a different calculation. Also notice that we are using the binary executable here.   It is created upon successful `cargo run` and/or `cargo build`.
  • 42. Let us look at the cobraLet us look at the cobra
  • 43. No not the movie Cobra with Slyvester Stallone!No not the movie Cobra with Slyvester Stallone! Let us look at the Golang CLI Library.Let us look at the Golang CLI Library.
  • 44. Here we create a cli application with cobra init command! We then create a symbolic link to it in this directory Here we initialize a cobra yaml file for common info! Now we finally create our main calculator logic.
  • 45. Here is bulk of the logic for add, subtract, multiply, and divide We have a cobra.Command and supply our function to run!
  • 46. The first command runs the add subcommand. The second command builds the binary executable. The third command runs the binary executable and runs the subtract subcommand. Each command afterwards is demonstrating the other subcommands in the calculator program.
  • 48. Let's Check off parsing, serialization, andLet's Check off parsing, serialization, and deserialization of our Rust Bucket List Nextdeserialization of our Rust Bucket List Next
  • 49. Data Serialization, Deserialization and Parsing inData Serialization, Deserialization and Parsing in Rust CLIsRust CLIs TheThe  crate crateserdeserde TheThe  book bookserdeserde
  • 50. We will write a command line application in Rust.   It will base64 decode a json web token to standard output Use statements Library Dependencies
  • 51. Here are 3 Structs and notice that the Token struct has both the Header and Claims struct embedded in it. The new methods for the Claims and Headers structs instantiate a new Claims and Header instance.
  • 52. Here is the main program.Here is the main program.
  • 54. Having some ascii fun now in the command line
  • 55. Having some ascii fun now in the command line This C program generates ascii characters to standard output. ./ascii_table | sed "s;.;'&',;g" | pbcopy This shell command replaces the output with double quotes and a comma and copies standard output to system clipboard
  • 56. The main rust program just prints some ascii characters to standard output for fun!!
  • 57. Time to shred some web scraping waves!!Time to shred some web scraping waves!!
  • 58. Here are our dependencies for the Web Scraping project: Here is our use and crate statements:
  • 59. Here is the main logic for the Web Scraping Project
  • 60. Here is the main function: Notice that we ran the run() function and wrap it in a `if let` statement which will print error and exit if there is an error.
  • 63. Printing values with println! macro in RustPrinting values with println! macro in Rust
  • 64. Printing with named value Pretty Print with println("{:#?}", something);
  • 65. Debugging Rust applications with rust-lldb. There are 2 debuggers that come prebundled with cargo: rust-lldb rust-gdb If you are working on Mac OS X it is easier to use rust-lldb You can use gdb in Mac OS X but it requires extra steps: First install gdb, easiest way is via homebrew package manager Next you will need to codesign gdb, if you are interested follow the steps in this CODESIGN-GIST
  • 66. For the purposes of this demo we will use rust-lldb Here we start rust-lldb using the compiled binary executable Notice here that we run the main.rs file by issuing the command run
  • 67. Let us set a breakpoint in lldb This is the short form version of setting a breakpoint This is the longer but more powerful way to set breakpoint
  • 68. Let us run our program with breakpoint set Notice here that lldb stopped in line 6 which is our breakpoint! We issued command "frame variable args" to see variable Note that the commands for printing: p (simple types), po (objects), and pa (arrays) don't work as well with Rust. The frame command is used to examine current stack frame and has various subcommands such as variable which work better!
  • 69. Step over with lldb Resume/Continue execution of program Notice here that we continued until the next breakpoint!
  • 70. List breakpoints Delete all breakpoints Delete specific breakpoint(s)
  • 71. First do Instruction level single step, stepping over calls Next actually step into function
  • 72. Next let us step over and then print value of variable Step out of the function
  • 73. Get stack frame information and continue execution Use expression to set values in running program
  • 74. Print back trace information Kill lldb session
  • 76. How to find me:How to find me: @ Github@ Githubjbelmontjbelmont @ Twitter@ Twitterjbelmont80jbelmont80 Personal website @Personal website @ marcelbelmont.commarcelbelmont.com @ LinkedIn@ LinkedInJean-Marcel BelmontJean-Marcel Belmont Checkout my new book titled Hands On Continuous Integration with Jenkins, Travis, and Circle CI