Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

1

Share

Download to read offline

Александр Воронов | Building CLI with Swift

Download to read offline

Расскажу об использовании Swift для построения CLI инструментов и написании скриптов. А так же, что нам для этого понадобится. И, конечно же, рассмотрим плюсы и минусы нового игрока на поле :)

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all

Александр Воронов | Building CLI with Swift

  1. 1. IT Saturday • @aleks_voronov • Stanfy BUILDING CLI WITH SWIFT ALEXANDER VORONOV, STANFY @aleks_voronov
  2. 2. IT Saturday • @aleks_voronov • Stanfy REASON WHY?
  3. 3. IT Saturday • @aleks_voronov • Stanfy OTHER PLATFORMS
  4. 4. IT Saturday • @aleks_voronov • Stanfy JAVASCRIPT NODEJS NPM BOWER GULP GRUNT
  5. 5. IT Saturday • @aleks_voronov • Stanfy RUBY RACK RAILS SINATRA RUBYGEMS RAKE
  6. 6. IT Saturday • @aleks_voronov • Stanfy PYTHON PYPI PIP …
  7. 7. IT Saturday • @aleks_voronov • Stanfy SWIFT COCOAPODS CARTHAGE SPM PERFECT COMMANDANT
  8. 8. IT Saturday • @aleks_voronov • Stanfy FULLSTACK MULTIPLATFORM
  9. 9. IT Saturday • @aleks_voronov • Stanfy FULLSTACK MULTIPLATFORM
  10. 10. IT Saturday • @aleks_voronov • Stanfy WHAT IS CLI?
  11. 11. IT Saturday • @aleks_voronov • Stanfy WHAT IS CLI?
  12. 12. IT Saturday • @aleks_voronov • Stanfy CLI ARGUMENTS
  13. 13. IT Saturday • @aleks_voronov • Stanfy POSIX STANDARD 📘 SHORT FLAGS $ ls -a $ ruby -v $ git commit -m "..."
  14. 14. IT Saturday • @aleks_voronov • Stanfy GNU STANDARD 📙 LONG FLAGS $ ls --all $ ruby --version $ git commit --message "..."
  15. 15. IT Saturday • @aleks_voronov • Stanfy COMBINED FLAGS 🏴 $ git commit -a -m "..." $ git commit -am "..."
  16. 16. IT Saturday • @aleks_voronov • Stanfy SUBCOMMANDS 🏘 $ git log -2 $ git status $ git commit -am "..."
  17. 17. IT Saturday • @aleks_voronov • Stanfy STANDARD IO 📥📤 0 - STDIN 1 - STDOUT 2 - STDERR
  18. 18. IT Saturday • @aleks_voronov • Stanfy 0 - STDIN 1 - STDOUT 2 - STDERR $ cat nofile > cat: nofile: No such file or directory
  19. 19. IT Saturday • @aleks_voronov • Stanfy 0 - STDIN 1 - STDOUT 2 - STDERR $ cat nofile 2>>err.log
  20. 20. IT Saturday • @aleks_voronov • Stanfy 0 - STDIN 1 - STDOUT 2 - STDERR $ cat nofile 2>&1
  21. 21. IT Saturday • @aleks_voronov • Stanfy 0 - STDIN 1 - STDOUT 2 - STDERR $ cat nofile 2>>err.log 1>>out.log
  22. 22. IT Saturday • @aleks_voronov • Stanfy 0 - STDIN 1 - STDOUT 2 - STDERR $ cat nofile 2>/dev/null
  23. 23. IT Saturday • @aleks_voronov • Stanfy 0 - STDIN 1 - STDOUT 2 - STDERR $ cat nofile 2>&1 | grep kernel
  24. 24. IT Saturday • @aleks_voronov • Stanfy UNIX PIPELINES ⛓ $ ls -l | grep "Mar" | sort
  25. 25. IT Saturday • @aleks_voronov • Stanfy UNIX PIPELINES ⛓ $ ps aux | grep Xcode | awk '{print $2}'
  26. 26. IT Saturday • @aleks_voronov • Stanfy UNIX PIPELINES ⛓ $ git branch | xargs git branch -D 😈
  27. 27. IT Saturday • @aleks_voronov • Stanfy CLI WITH SWIFT 🖥
  28. 28. IT Saturday • @aleks_voronov • Stanfy SWIFT REPL 🔃 (READ-EVALUATION-PRINT-LOOP) $ swift
  29. 29. IT Saturday • @aleks_voronov • Stanfy IMMEDIATE MODE 🚀 $ swift script.swift
  30. 30. IT Saturday • @aleks_voronov • Stanfy SWIFT COMPILE ⚙ $ swiftc script.swift $ ./script
  31. 31. IT Saturday • @aleks_voronov • Stanfy SWIFT COMPILE ⚙ $ swiftc script.swift -o myscript $ ./myscript
  32. 32. IT Saturday • @aleks_voronov • Stanfy EXECUTABLE SCRIPTS 💾
  33. 33. IT Saturday • @aleks_voronov • Stanfy EXECUTABLE SCRIPTS #!/USR/BIN/SWIFT HASHBANG
  34. 34. IT Saturday • @aleks_voronov • Stanfy EXECUTABLE SCRIPTS CHMOD +X SCRIPT.SWIFT
  35. 35. IT Saturday • @aleks_voronov • Stanfy SCALING OUR CLI 🏗 WORKING WITH MULTIPLE FILES
  36. 36. IT Saturday • @aleks_voronov • Stanfy MAIN.SWIFT 👑
  37. 37. IT Saturday • @aleks_voronov • Stanfy EXECUTING MULTIPLE FILES📄📄 $ swift main.swift script.swift
  38. 38. IT Saturday • @aleks_voronov • Stanfy $ swiftc main.swift script.swift -o script EXECUTING MULTIPLE FILES📄📄
  39. 39. IT Saturday • @aleks_voronov • Stanfy $ swiftc script.swift main.swift -o script EXECUTING MULTIPLE FILES📄📄
  40. 40. IT Saturday • @aleks_voronov • Stanfy $ swiftc *.swift -o script EXECUTING MULTIPLE FILES📄📄
  41. 41. IT Saturday • @aleks_voronov • Stanfy $ find . -iname '*.swift' | xargs swiftc -o script EXECUTING MULTIPLE FILES📄📄
  42. 42. IT Saturday • @aleks_voronov • Stanfy EXTERNAL RESOURCES 🎁
  43. 43. IT Saturday • @aleks_voronov • Stanfy SYSTEM DEPENDENCIES 💼 $ swiftc script.swift $ xcrun -sdk macosx swiftc script.swift
  44. 44. IT Saturday • @aleks_voronov • Stanfy CUSTOM DEPENDENCIES 🛠 -F $ swift -F /Carthage/Build/Mac script.swift
  45. 45. IT Saturday • @aleks_voronov • Stanfy CUSTOM DEPENDENCIES #!/USR/BIN/SWIFT -F Carthage/Build/Mac HASHBANG
  46. 46. IT Saturday • @aleks_voronov • Stanfy COMPILING DEPENDENT SCRIPT 🤖
  47. 47. IT Saturday • @aleks_voronov • Stanfy $ xcrun -sdk macosx swiftc -F Carthage/Build/Mac script.swift COMPILING DEPENDENT SCRIPT > dyld: Library not loaded: @rpath
  48. 48. IT Saturday • @aleks_voronov • Stanfy $ xcrun -sdk macosx swiftc -F Carthage/Build/Mac script.swift -Xlinker -rpath -Xlinker @executable_path/Carthage/Build/Mac COMPILING DEPENDENT SCRIPT
  49. 49. IT Saturday • @aleks_voronov • Stanfy DEPENDENCIES MANAGEMENT 🍴
  50. 50. IT Saturday • @aleks_voronov • Stanfy COCOAPODS 🤔
  51. 51. IT Saturday • @aleks_voronov • Stanfy CARTHAGE 😏
  52. 52. IT Saturday • @aleks_voronov • Stanfy SPM 😳 SWIFT PACKAGE MANAGER
  53. 53. IT Saturday • @aleks_voronov • Stanfy PARSING ARGUMENTS 📬
  54. 54. IT Saturday • @aleks_voronov • Stanfy PARSING ARGUMENTS $ ./script one two three $ ./script one two three $ ./script "one two three" 3 args 1 arg 1 arg
  55. 55. IT Saturday • @aleks_voronov • Stanfy PROCESS ENUM Process.arguments == [ "./script.swift", "one", "two", "three" ]
  56. 56. IT Saturday • @aleks_voronov • Stanfy FILESYSTEM 🗄
  57. 57. IT Saturday • @aleks_voronov • Stanfy FILESYSTEM NSFILEMANAGER NSFILEHANDLER NSTASK NSPIPE
  58. 58. IT Saturday • @aleks_voronov • Stanfy HANDY LIBRARIES
 🏛 COMMANDER OPTIONKIT COMMANDANT REACTIVETASKS PRETTYCOLORS
  59. 59. IT Saturday • @aleks_voronov • Stanfy REAL WORLD EXAMPLES 🌍 CARTHAGEKIT
 CARTHAGE CLI
  60. 60. IT Saturday • @aleks_voronov • Stanfy THANK YOU!
  61. 61. IT Saturday • @aleks_voronov • Stanfy Q/A @ALEKS_VORONOV A-VORONOV
  • VitaliiPiskovyi

    Mar. 22, 2016

Расскажу об использовании Swift для построения CLI инструментов и написании скриптов. А так же, что нам для этого понадобится. И, конечно же, рассмотрим плюсы и минусы нового игрока на поле :)

Views

Total views

459

On Slideshare

0

From embeds

0

Number of embeds

104

Actions

Downloads

2

Shares

0

Comments

0

Likes

1

×