Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift-argument-parser support #369

Open
Kyle-Ye opened this issue Nov 15, 2021 · 4 comments
Open

Swift-argument-parser support #369

Kyle-Ye opened this issue Nov 15, 2021 · 4 comments
Labels
enhancement New feature or request

Comments

@Kyle-Ye
Copy link
Contributor

Kyle-Ye commented Nov 15, 2021

Can we use swift-argument-parser to replace vapor'console-kit. All the commands and help text will remain the same. But the code is more clear and more maintainable (in my opinion) since more people are familiar with swift-argument-parser than console-kit.

If the maintainer agree on this, I can try to make a PR for it.

@Kyle-Ye Kyle-Ye added the enhancement New feature or request label Nov 15, 2021
@Kyle-Ye Kyle-Ye closed this as completed Dec 16, 2021
@0xTim
Copy link
Member

0xTim commented Dec 16, 2021

@Kyle-Ye sorry for not getting around to it. The long term goal is to move both the toolbox and Vapor itself over to using Swift Argument Parser. However I believe when we tried it there were missing features like colour support in the terminal that would block us (and make us unable to do it in a non-breaking way)

@Kyle-Ye
Copy link
Contributor Author

Kyle-Ye commented Dec 16, 2021

@Kyle-Ye sorry for not getting around to it. The long term goal is to move both the toolbox and Vapor itself over to using Swift Argument Parser. However I believe when we tried it there were missing features like colour support in the terminal that would block us (and make us unable to do it in a non-breaking way)

Maybe we could add a feature request to Swift Argument Parser to support colorful output?

Or just implement the feature ourselves in a fork and hopefully it will be merged into the main branch of SAP.

@Kyle-Ye
Copy link
Contributor Author

Kyle-Ye commented Dec 16, 2021

It's such a common feature to support colorful output.

I maintain a CLI tool in my company and also use Swift Argument Parser as a start point. To support colorful output I just manually add something below

import Foundation

/// USAGE:
/// "\("only this string will be green!", color: .green)"
public enum ASCIIColor: String, CaseIterable {
    case black = "\u{001B}[0;30m"
    case red = "\u{001B}[0;31m"
    case green = "\u{001B}[0;32m"
    case yellow = "\u{001B}[0;33m"
    case blue = "\u{001B}[0;34m"
    case magenta = "\u{001B}[0;35m"
    case cyan = "\u{001B}[0;36m"
    case white = "\u{001B}[0;37m"
    case `default` = "\u{001B}[0;0m"
}

extension DefaultStringInterpolation {
    mutating func appendInterpolation<T: CustomStringConvertible>(_ value: T, color: ASCIIColor) {
        appendInterpolation("\(color.rawValue)\(value)\(ASCIIColor.default.rawValue)")
    }
}

public func echo(with string: String, color: ASCIIColor = .default) {
    print("\(string, color: color)")
}

But it seems hard to do it if we want the parsed-command output to be colorful like what currently we are

截屏2021-12-16 19 42 43

@Kyle-Ye Kyle-Ye reopened this Dec 16, 2021
@0xTim
Copy link
Member

0xTim commented Dec 16, 2021

It's definitely something they should support longer term I think

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants