Skip to content

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
@nekrich nekrich force-pushed the feature/enumsAsArguments branch from bcef806 to 3fd4b4c Compare November 28, 2017 13:19
@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants