Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Commit

Permalink
Clean up with Fantomas
Browse files Browse the repository at this point in the history
  • Loading branch information
mavnn committed Jul 4, 2013
1 parent 7cef714 commit f795575
Show file tree
Hide file tree
Showing 8 changed files with 552 additions and 374 deletions.
80 changes: 41 additions & 39 deletions NuGetPlus.Console/Program.fs
Original file line number Diff line number Diff line change
@@ -1,90 +1,92 @@
module NuGetPlay.Main

open System
open NuGet
open NuGetPlus.ProjectManagement
open UnionArgParser

type Argument =
| [<MandatoryAttribute>] Action of string
| [<MandatoryAttribute>] ProjectFile of string

This comment has been minimized.

Copy link
@ovatsus

ovatsus Jul 4, 2013

Here, this two attributes were removed. Please report the bug to fantomas

This comment has been minimized.

Copy link
@mavnn

mavnn Jul 4, 2013

Author Owner

I've raised this and the other issue I discovered.

type Argument =
| Action of string
| ProjectFile of string
| PackageId of string
| Version of string
with
interface IArgParserTemplate with
member s.Usage =
match s with
| Action _ -> "Specify an action: Install, Remove, Restore or Update"
| ProjectFile _ -> "Path to project file to update."
| PackageId _ -> "NuGet package id for action."
| Version _ -> "Optional specific version of package."
interface IArgParserTemplate with
member s.Usage =
match s with
| Action _ ->
"Specify an action: Install, Remove, Restore or Update"
| ProjectFile _ -> "Path to project file to update."
| PackageId _ -> "NuGet package id for action."
| Version _ -> "Optional specific version of package."

type ActionType =
type ActionType =
| Install
| Remove
| Restore
| Update

let processAction (a : string) =
let processAction(a : string) =
match a.ToLower() with
| "install" -> Install
| "remove" -> Remove
| "restore" -> Restore
| "update" -> Update
| _ -> failwith "Invalid Action; please use install, remove, restore or update."
| _ ->
failwith
"Invalid Action; please use install, remove, restore or update."

let processProjectFile (f : string) =
let processProjectFile(f : string) =
match IO.File.Exists(f) with
| true -> f
| false -> failwith "ProjectFile does not exist."

let processVersion (v : string) =
SemanticVersion(v)
let processVersion(v : string) = SemanticVersion(v)

[<EntryPoint>]
let main argv =
try
try
let parser = UnionArgParser<Argument>()
let results = parser.Parse()
let action = results.PostProcessResult <@ Action @> processAction
let proj = results.PostProcessResult <@ ProjectFile @> processProjectFile
let proj =
results.PostProcessResult <@ ProjectFile @> processProjectFile
let maybePackage = results.TryGetResult <@ PackageId @>
let version = results.TryPostProcessResult <@ Version @> processVersion

printfn "Action type: %A" action
printfn "Project file: %s" proj
match maybePackage with
| Some package ->
printfn "Package ID: %s" package
| Some package -> printfn "Package ID: %s" package
| None -> ()

match version with
| None -> ()
| Some v -> printfn "Version: %A" v

let checkPackage mp =
let checkPackage mp =
match mp with
| None ->
failwith "A package is required for this action"
| None -> failwith "A package is required for this action"
| Some p -> p

match action with
| Install ->
| Install ->
match version with
| None -> InstallReference proj (checkPackage maybePackage)
| Some v -> InstallReferenceOfSpecificVersion proj (checkPackage maybePackage) v
| Update ->
| Some v ->
InstallReferenceOfSpecificVersion proj
(checkPackage maybePackage) v
| Update ->
match version with
| None -> UpdateReference proj (checkPackage maybePackage)
| Some v -> UpdateReferenceToSpecificVersion proj (checkPackage maybePackage) v
| Remove ->
RemoveReference proj (checkPackage maybePackage)
| Restore ->
| Some v ->
UpdateReferenceToSpecificVersion proj
(checkPackage maybePackage) v
| Remove -> RemoveReference proj (checkPackage maybePackage)
| Restore ->
match maybePackage with
| Some package -> failwith "PackageId provided for restore action - restore will always restore the whole packages.config"
| Some package ->
failwith
"PackageId provided for restore action - restore will always restore the whole packages.config"
| None -> ()
RestoreReferences proj
0
with
| ex ->
with
| ex ->
printfn "%A" ex
1
1

2 comments on commit f795575

@ovatsus
Copy link

@ovatsus ovatsus commented on f795575 Jul 4, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was the removal of [] intentional or did fantomas just drop it and it's a bug?

@mavnn
Copy link
Owner Author

@mavnn mavnn commented on f795575 Jul 4, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where? (you can comment on individual lines as well)

It wasn't intentional, to answer the question :).

I'm also undecided whether to keep on using it on the TickSpec step definition files, I'm not sure if I prefer the consistency or having the attributes inline to match the steps better. For the moment though I'm going to try and stick with Go style format everything all the time for a while and see how it goes. Should help providing feedback for Anh-Dung Phan as well.

Please sign in to comment.