Skip to content
New issue

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

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

Already on GitHub? # to your account

Strict arguments values support. #117

Merged
merged 2 commits into from
Nov 29, 2017

Conversation

nekrich
Copy link
Contributor

@nekrich nekrich commented Nov 22, 2017

Hi.

This PR will allow making strict arguments values in a more comfortable way.
Problem:
  Having: 2 projects, 4 deployment environments.
  Task: download resources for concrete one project & one environment.
  Problem: Should get string parameter, make init(rawValue: _), check if nil, throw an error.

With this PR we will get RawRepresentable arguments (where RawValue is StringProtocol or FixedWidthInteger) from the box:

enum DeploymentEnvironment: String, ArgumentProtocol {
    static let name: String = "Deployment environment"
    
    case dev, qa, stage, release
}

enum Project: String, ArgumentProtocol {
    static let name: String = "Project"
    
    case projectA, projectB
}

struct DownloadResourcesOptions: OptionsProtocol {
    
    let project: Project
    let environment: DeploymentEnvironment
    let outputTo: String
    
    static func create(_ p: Project) -> (DeploymentEnvironment) -> (String) -> DownloadResourcesOptions {
        return { e in { o in
            DownloadResourcesOptions(project: p, environment: e, outputTo: o)
            } }
    }
    
    static func evaluate(_ commandMode: CommandMode) -> Result<DownloadResourcesOptions, CommandantError<CommandantError<DownloadResourcesOptionsError>>>
    {
        return create
            <*> commandMode <| Option(key: "project", defaultValue: .projectA, usage: """
project name to download new localizations files for.
Available options: 'projectA' (default) or 'projectB',
""")
            <*> commandMode <| Option(key: "env", defaultValue: .dev, usage: """
deployment environment where to take new localizations files.
Available options: 'dev' (default), 'qa', 'stage', 'release'.
""")
            <*> commandMode <| Argument(usage: "path to output new localization files")
    }
}

…ments

# Conflicts:
#	Commandant.xcodeproj/project.pbxproj
#	Tests/LinuxMain.swift
@mdiep
Copy link
Member

mdiep commented Nov 29, 2017

Thanks for the pull request! (Any sorry for the delayed review.)

This all looks good. 👍

@mdiep mdiep merged commit e6ad5d0 into Carthage:master Nov 29, 2017
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants