Coder Social home page Coder Social logo

moderator's People

Contributors

kaiede avatar kareman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

moderator's Issues

New syntax?

In Swift 3 version of SwiftShell this code was working perfectly:

`let unavailState: String = run("/bin/bash", with: [ "-c", "/usr/local/bin/zpool status | grep state | grep -w UNAVAIL | wc -l"])
let trimUnavail = unavailState.trimmingCharacters(in: .whitespacesAndNewlines)

let degradedState: String = run("/bin/bash", with: [ "-c", "/usr/local/bin/zpool status | grep state | grep -w DEGRADED | wc -l"])
let trimDegraded = degradedState.trimmingCharacters(in: .whitespacesAndNewlines)

let offlineState: String = run("/bin/bash", with: ["-c", "/usr/local/bin/zpool status | grep state | grep -w OFFLINE | wc -l"])
let trimOffline = offlineState.trimmingCharacters(in: .whitespacesAndNewlines)

let faultedState: String = run("/bin/bash", with: ["-c", "/usr/local/bin/zpool status | grep state | grep -w FAULTED | wc -l"])
let trimFaulted = faultedState.trimmingCharacters(in: .whitespacesAndNewlines)

let removedState: String = run("/bin/bash", with: ["-c", "/usr/local/bin/zpool status | grep state | grep -w REMOVED | wc -l"])
let trimRemoved = removedState.trimmingCharacters(in: .whitespacesAndNewlines)

let onlineState: String = run("/bin/bash", with: ["-c", "/usr/local/bin/zpool status | grep state | grep -w ONLINE | wc -l"])
let trimOnline = onlineState.trimmingCharacters(in: .whitespacesAndNewlines)
But now, it throw an error while compiling:Argument labels '(_:, with:)' do not match any available overloads`

So, what is new way to do the same thing?

Supporting Both Swift 3 and Swift 4

I’m using Swift on a Raspberry Pi for aquarium automation. The issue is that we are stuck with Swift 3.1.1 for the time being, but still want to leverage libraries like this one. And this one was the easiest to bootstrap back into Swift 3 for my purposes.

I’ve put together a set of changes in my fork that add extensions to String for the Swift 4-only APIs you call, based on the original Swift 3 code you had. I also changed the Travis yml file so that CI builds check both 3.1.1 and 4.1.2. While I wouldn’t expect folks to test against both versions of Swift, and they could accidentally use a Swift 4 API without thinking of compatibility, the CI should help catch those sorts of issues.

The one change I had to make that I’m not entirely happy with has to do with the empty tuple you use during a map to save space. The code doesn’t care about the result, so it makes sense, but it only really works in Swift 4. Swift 3 complains about using an empty tuple in this way. I made it work by using a Bool instead, but perhaps there’s a better approach here that I’m missing.

I can send the Pull Request along as it has been working well for my project, and Travis is happy, except that flatMap apparently just got deprecated in Swift 4.1 (just a warning for now). Go figure.

Arguments with spaces in the value?

Is there a way to create an argument that allows spaces in it?

I am trying to use Moderator for a swift script to post a message to the Slack API. How can i pass in a "message" argument that may have spaces in it? Wrapping my message argument value in quotes does not seem to work.

I imagine I could write my messages to a file, and pass in the filename, but I was curious if there is any other way with the current Moderator implementation.

import Foundation
import Moderator
import SwiftShell

let arguments = Moderator(description: "Post a message to Slack.")

let messageArg = arguments.add(Argument<String?>.optionWithValue("m", name: "message", description: "The message to post."))
let botNameArg = arguments.add(Argument<String?>.optionWithValue("n", name: "name", description: "The name of the bot."))
let urlSlugArg = arguments.add(Argument<String>.optionWithValue("p", name: "path", description: "The url path (the part after https://hooks.slack.com/services/)."))

do {
    try arguments.parse()

    guard let message = messageArg.value else {
        throw ArgumentError(errormessage: "Slack message not found.", usagetext: "use -m Message")
    }

    guard let urlSlug = urlSlugArg.value else {
        throw ArgumentError(errormessage: "Slack URL path not found.", usagetext: "use -p T000000/B000000/XXXXXXX")
    }

    guard let botName = botNameArg.value else {
        throw ArgumentError(errormessage: "Bot name not found.", usagetext: "use -n BotName")
    }

    } catch {
        print("*** FAILURE!")
        print(error)
        exit(Int32(error._code))
    }

Here is what happens with my current script. I am trying to get the "m" argument to contain spaces:

$ marathon run post-to-slack.swift -m Message! -p T00000000/B00000000/XXXXXXXXXXXX -n Bot

$ marathon run post-to-slack.swift -m Longer Message! -p T0000000/B0000000/XXXXXXXXXXXX -n Bot
*** FAILURE!
Unknown arguments: Message!
Post a message to Slack.

Usage: post-to-slack
  -m <message>:
      The message to post.
  -n <name>:
      The name of the bot.
  -p <path>:
      The url path (the part after https://hooks.slack.com/services/).

$ marathon run post-to-slack.swift -m "Longer Message!" -p T00000000/B00000000/XXXXXXXXXXXXXX -n Bot
-bash: !": event not found

Thanks you for any guidance you can help provide. Loving your tools.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.