Rectangle 27 7

If the URL that you are trying to remove the query string from is the current URL of the PHP script, you can use one of the previously mentioned methods. If you just have a string variable with a URL in it and you want to strip off everything past the '?' you can do:

$pos = strpos($url, "?");
$url = substr($url, 0, $pos);

+1 because its the only other answer here that answers the question and provides an alternative.

You should consider that the URL might not contain a ?. Your code will then return an empty string.

url - Beautiful way to remove GET-variables with PHP? - Stack Overflow

php url variables get
Rectangle 27 5

I agree with @Dennis -- unless you want the Url to change, then you'll have to think of something else. The reason is that RedirectToAction doesn't serialize the data, it simply iterates over the properties in the route values object constructing a query string with the keys being the property names and the values the string representation of the property values. If you want to have the Url change, then using TempData is probably the easiest way to do this, although you could also store the item in the database, pass the id to the Result method, and reconstitute it from there.

Hi T, I ended up using the TempDaata trick to transfer objects from one action to the other. Thanks for clearing up how RedirectToAction works. That was the real confusing part for me.

asp.net mvc - RedirectToAction(..) with complex deep object fails - St...

asp.net-mvc
Rectangle 27 5

I agree with @Dennis -- unless you want the Url to change, then you'll have to think of something else. The reason is that RedirectToAction doesn't serialize the data, it simply iterates over the properties in the route values object constructing a query string with the keys being the property names and the values the string representation of the property values. If you want to have the Url change, then using TempData is probably the easiest way to do this, although you could also store the item in the database, pass the id to the Result method, and reconstitute it from there.

Hi T, I ended up using the TempDaata trick to transfer objects from one action to the other. Thanks for clearing up how RedirectToAction works. That was the real confusing part for me.

asp.net mvc - RedirectToAction(..) with complex deep object fails - St...

asp.net-mvc
Rectangle 27 5

Another solution... I find this function more elegant, it will also remove the trailing '?' if the key to remove is the only one in the query string.

/**
 * Remove a query string parameter from an URL.
 *
 * @param string $url
 * @param string $varname
 *
 * @return string
 */
function removeQueryStringParameter($url, $varname)
{
    $parsedUrl = parse_url($url);
    $query = array();

    if (isset($parsedUrl['query'])) {
        parse_str($parsedUrl['query'], $query);
        unset($query[$varname]);
    }

    $path = isset($parsedUrl['path']) ? $parsedUrl['path'] : '';
    $query = !empty($query) ? '?'. http_build_query($query) : '';

    return $parsedUrl['scheme']. '://'. $parsedUrl['host']. $path. $query;
}
$urls = array(
    'http://www.example.com?test=test',
    'http://www.example.com?bar=foo&test=test2&foo2=dooh',
    'http://www.example.com',
    'http://www.example.com?foo=bar',
    'http://www.example.com/test/no-empty-path/?foo=bar&test=test5',
    'https://www.example.com/test/test.test?test=test6',
);

foreach ($urls as $url) {
    echo $url. '<br/>';
    echo removeQueryStringParameter($url, 'test'). '<br/><br/>';
}
http://www.example.com?test=test
http://www.example.com

http://www.example.com?bar=foo&test=test2&foo2=dooh
http://www.example.com?bar=foo&foo2=dooh

http://www.example.com
http://www.example.com

http://www.example.com?foo=bar
http://www.example.com?foo=bar

http://www.example.com/test/no-empty-path/?foo=bar&test=test5
http://www.example.com/test/no-empty-path/?foo=bar

https://www.example.com/test/test.test?test=test6
https://www.example.com/test/test.test

url - Beautiful way to remove GET-variables with PHP? - Stack Overflow

php url variables get
Rectangle 27 3

If you simply want to redirect a client to remove the query string (everything after the ? in the URL), then you can try this:

You've got most of it right, it seems, but your rule needs to have a match, and your target (the http://www.somesite.com/) needs a ? at the end so that any query string before the rewrite won't get appended.

In Apache 2.4 or newer you can use the QSD query string discard flag:

RewriteEngine On
RewriteCond %{QUERY_STRING} x=(.*)
RewriteRule .* http://www.somesite.com/ [R=301,L,QSD]

.htaccess - Remove variable from base URL with htaccess - Stack Overfl...

.htaccess url variables
Rectangle 27 5

This is because your routes contain the id parameter. Remove it from the routes and Url.Action will change the URL and add your parameter to the query string.

The id parameter will be put after the last slash if you specify it with Url.Action.

routes.MapRoute("Default", "{controller}/{action}",
    new { controller = "Home", action = "Index" });

The resulting URL will have a query string containing the id.

c# - @Html.Action MVC 4 with QueryString Parameters - Stack Overflow

c# asp.net-mvc asp.net-mvc-4 razor asp.net-mvc-routing
Rectangle 27 2

The framework is telling you that the link you are clicking on to call the Edit and Delete action methods is not providing an int parameter named id which the action method is expecting to find somewhere in the submitted data. This is usually provided either in the URL, query string or submitted variables.

If that is not enough for you to spot the problem, post your view code specially the section related to the links.

Hi @JTMon...Thanks for your quick reply... I forget to add "new { id=item.Srno }" in the ActionLink for Edit, Details and Delete...

asp.net mvc - The parameters dictionary contains a null entry for para...

asp.net-mvc asp.net-mvc-4
Rectangle 27 4

Very good question. Unfortunately it is not easy to generate an url which has multiple query string parameters with the same name using the Html.ActionLink helper. So I can see two possible solutions:

  • Write a custom model binder for long[] that is capable of parsing a comma separated values. This way you can keep your GetRoute method which will generate the following url: period=9&events=1%2C3&recordsPerPage=10&page=5. public class CommaSeparatedLongArrayModelBinder : DefaultModelBinder { public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { var values = bindingContext.ValueProvider.GetValue(bindingContext.ModelName); if (values != null && !string.IsNullOrEmpty(values.AttemptedValue)) { // TODO: A minimum of error handling would be nice here return values.AttemptedValue.Split(',').Select(x => long.Parse(x)).ToArray(); } return base.BindModel(controllerContext, bindingContext); } } which you will register in Application_Start: ModelBinders.Binders.Add(typeof(long[]), new CommaSeparatedLongArrayModelBinder()); and then the following controller action will be able to understand the previous URL: public ActionResult Foo(long[] events, int page, int period, int recordsPerPage) { ... }
  • Manually generate this anchor: <a href="@string.Format("{0}?{1}&page=5", Url.Action("action", "controller"), Request.QueryString)">abc</a>

It was a good answer and I almost thought it would work at first try ... but we're talking about programming, and it never does. The problem I had is the generated link now looks like /5?period=9events=1events=3recordsPerPage=10&amp;page=2

@Bruno, I would probably go with a custom model binder. As far as the second part of my answer is concerned I've fixed it by removing the Html.AttributeEncode call which is not necessary in this case.

Global.asax

c# - How to deal with more than one value per key in ASP.NET MVC 3? - ...

c# asp.net-mvc-3 dictionary mvccontrib
Rectangle 27 4

You don't show your routes, but you're almost certainly hitting different routes in this example. The argument to your action must be named the same as the token in the route in order for the generated URL to match the route token with the lambda form of ActionLink. Anything which does not match a routing token will be appended as a query string parameter, as with your second URL. Seeing the query string parameter is strong evidence that the name you passed implicitly ("property" in this case) does not match a route token. Since you get different results with the same token name, I thereby conclude you are hitting different routes. Incidentally, I recommend building links with RouteLink instead of ActionLink, so that you can be certain of which route you will match.

.net - ASP.NET MVC Html.ActionLink result URL - the way of encoding - ...

.net asp.net-mvc routing html-helper actionlink
Rectangle 27 1

It has changed because that route is included as the first route, so when MVC tries to generate a url it will always find that one. Because it has no segments or default values, the route always match and any parameters like the controller/action are included as query string values.

You can add a segment in the route definition for scriptName (even if it wont be used by your route handler). That way, this route wont be picked when generating a Url unless you pass a value for scriptName.

Another option would be setting a default value for controller, that matches none of your controllers. This way when generating urls in MVC, this route would always be excluded as none of your controllers will match that value. This should have no other effect when resolving incoming routes, as you use your custom route handler.

RouteTable.Routes.Insert(0,
    new Route(
        "common/scripts",    
        new RouteValueDictionary(new { controller = "AControllerThatDoesntExists"}),
        new EmbeddedScriptRouteHandler()
    )
);

asp.net mvc - MVC custom route and BeginForm behaviour - Stack Overflo...

asp.net-mvc asp.net-mvc-routing html.beginform
Rectangle 27 3

public static class ImageHelpers
    {
        /// <summary>
        /// return image link
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="id">Id of link control</param>
        /// <param name="controller">target controller name</param>
        /// <param name="action">target action name</param>
        /// <param name="strOthers">other URL parts like query string, etc</param>
        /// <param name="strImageURL">URL for image</param>
        /// <param name="alternateText">Alternate Text for the image</param>
        /// <param name="strStyle">style of the image like border properties, etc</param>
        /// <returns></returns>
        public static string ImageLink(this HtmlHelper helper, string id, string controller, string action, string strOthers, string strImageURL, 
            string alternateText, string strStyle, string cssClass = "imagelink")
        {
            return ImageLink(helper, id, controller, action, strOthers, strImageURL, alternateText, strStyle, null, cssClass);
        }
        /// <summary>
        /// return image link
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="id">Id of link control</param>
        /// <param name="controller">target controller name</param>
        /// <param name="action">target action name</param>
        /// <param name="strOthers">other URL parts like query string, etc</param>
        /// <param name="strImageURL">URL for image</param>
        /// <param name="alternateText">Alternate Text for the image</param>
        /// <param name="strStyle">style of the image like border properties, etc</param>
        /// <param name="htmlAttributes">html attributes for link</param>
        /// <returns></returns>
        public static string ImageLink(this HtmlHelper helper, string id, string controller, string action, string strOthers, string strImageURL,
            string alternateText, string strStyle, object htmlAttributes, string cssClass = "imagelink")
        {
            // Create tag builder
            var divBuilder = new TagBuilder("div");
            divBuilder.AddCssClass(cssClass);

            var aBuilder = new TagBuilder("a");

            // Create valid id
            if (!string.IsNullOrEmpty(id))
                aBuilder.GenerateId(id);

            // Add attributes
            aBuilder.MergeAttribute("href", "/" + controller + "/" + action + strOthers); //form target URL
            aBuilder.InnerHtml = "<img src='" + strImageURL + "' alt='" + alternateText + "' class='" + cssClass + "' style='border: none;'/>" + alternateText; //set the image as inner html
            aBuilder.MergeAttributes(new RouteValueDictionary(htmlAttributes));

            divBuilder.InnerHtml = aBuilder.ToString(TagRenderMode.Normal); //to add </a> as end tag

            // Render tag
            return divBuilder.ToString(TagRenderMode.Normal);
        }
    }
@Html.ImageLink("", "Controller", "Action", "", 
  "~/images/whatever.png", "My test link", "imagelinkcssclass")

asp.net mvc 3 - How do I wrap an image in an ActionLink in MVC3? - Sta...

asp.net-mvc-3 image
Rectangle 27 2

Firstly, do not pass a complex object as a parameter to a GET method. Properties that are complex objects or collections will not bind (they will be null), you may exceed the query string limit (crashing your app) and then there the ugly url it creates. Just initialize a new Change in the method, or pass an ID and get the Change based on the ID.

Your view code looks OK although I suggest you use a label associated with the checkbox and the hidden input for the Access_Name property seems unnecessary

@for (int i = 0; i < Model.SecurityAccessList.Count; i++)
{
  @Html.CheckBoxFor(m => m.SecurityAccessList[i].IsSelected)
  @Html.LabelFor(m => m.SecurityAccessList[i].IsSelected, Model.SecurityAccessList[i].Access_Name)
  @Html.HiddenFor(m => m.SecurityAccessList[i].ID)
}

which should generate html with name attribute like

<input type=checkbox" name="SecurityAccessList[0].IsSelected" ...>
<input type=checkbox" name="SecurityAccessList[1].IsSelected" ...>

Next, remove the (awful) [Bind] attribute. By default, all properties are bound, which seems to be what you want to do, but in fact you have excluded SecurityAccessList (I think - tl;dr ) and included a whole lot of 'properties' that don't even exist in your model (Security_Access_To_1, Security_Access_To_2, .....). If you ever find your self needing to use [Bind(Include="..")], stop and use a view model to display/edit what you need instead.

The POST method should then correctly bind your model with change.SecurityAccessList containing the collection. Note I recommend you change your parameter to (say) model. In this case its OK, but there are plenty of question on SO about binding failing because the name of the parameter match the name of a model property.

The List<bTest> list = new List<bTest>(); bit where you create a SelectList for what seems to be used in a radio button list seems odd. A select list is not even appropriate for that usage and in any case your not even using the ID property of bTest. It may just as well be

SelectList sl = new SelectList(new List<string>() { "Add Access", "Remove Access", "Change Access" });

which produces exactly the same result, although I suspect all you need is the property to be List<string>

Next the ActiveDirectory objAD = new ActiveDirectory(); bit where your seem to be inserting a 'default' or null item for use in a select list is also wrong. Again the only property you use is displayName but in any case delete it and use the overload of DropDownListFor() that accepts optionLabel

@Html.DropDownListFor(m => m.YourProperty, Model.ADList, "-Please select-")
null
<option value>-Please Select-</option>
[Required]

Finally there the code inside the if (ModelState.IsValid) block which makes no sense. You don't even use the value of sb (not sure what its even for) and then your attempting to add the same instance of change into the database each time IsSelected=true, except that its only added once because as soon as it is added, you do a redirect.

Ok, I am able to retrieve my checkbox list but now I am having issues posting the comma separated values to a different table. How can I go about doing this. All I want is to post the data back to the Change Model in a column. I seem to be having trouble understanding how to get the values to post back to the database.

That's easy enough to do, but the question is WHY? You should not be storing comma separated values in a data base to represent relationships (the only case where it would be applicable if you stored an enum value decorated with the [Flags] attribute). And then of course you would need to parse it back again when reading the data. It's a little hard to understand exactly what your doing with tos code but I suspect you need a table with fields for the employeeID and the SecurityAccessListID or SecurityAccessListName

c# - How to HTTPPost ASP.Net MVC 5 CheckBoxList to database - Stack Ov...

c# asp.net asp.net-mvc entity-framework http-post
Rectangle 27 1

I think you're trying to hard to use GET. Try changing the request method to POST and put those query string parameters into the request body.

Long URL does not help SEO as well, does it?

I'm using GET for two reasons: 1) These URLs need to be shared, and need to be persistent 2) I'm not POSTing anything. This is a read operation. > Long URL does not help SEO as well, does it? I'm not sure, but if the request is complex, so is the query... no getting around that unless I use non-semantic URLs instead.

iis - ASP.NET MVC, Url Routing: Maximum Path (URL) Length - Stack Over...

asp.net-mvc iis url routing asp.net-routing
Rectangle 27 1

I think you're trying to hard to use GET. Try changing the request method to POST and put those query string parameters into the request body.

Long URL does not help SEO as well, does it?

I'm using GET for two reasons: 1) These URLs need to be shared, and need to be persistent 2) I'm not POSTing anything. This is a read operation. > Long URL does not help SEO as well, does it? I'm not sure, but if the request is complex, so is the query... no getting around that unless I use non-semantic URLs instead.

iis - ASP.NET MVC, Url Routing: Maximum Path (URL) Length - Stack Over...

asp.net-mvc iis url routing asp.net-routing
Rectangle 27 2

How are you generating that URL? With Routing, if those are meant to be in the query string, it should work fine. We only generate query string parameters for RouteValues that you specify.

One thing I've done in the past is to write my own helper method for specific links where I might pass in an object for route values, but want to clear out the values that I don't need before passing it to the underlying routing API. That worked well for me.

In this case it isn't being generated by the route, just a form using the get method to refine the query. Is there a better way to handle this?

It's been a while since I asked this question but this ended up being the solution I went with, thank you.

Removing null/empty keys from a query string in asp.net MVC - Stack Ov...

asp.net asp.net-mvc routing query-string url-routing
Rectangle 27 2

The major benefit to referencing Bundles in a view using Razor is the automatic creation of URLs to the bundle with a cache buster query string appended to it (so that when content of any of the files in the bundle change, the URL changes, and you don't need to worry about the client still referencing an older cached version of your bundle). A second benefit is that when debug=true (in web.config), it renders URLs directly to the items in the bundle.

You could, of course, just hardcode the path to the bundle in your plain HTML, but then you lose both of these features. I'm also not sure if it'll render the combined bundle if you go to the bundle URL when debug=true (meaning, it might not work when you are in debug mode on your dev machine).

What I'm getting at is that if you aren't using a Razor view for at least the initial page in your SPA (the page that bootstraps your Angular client), you're not going to find Bundles very useful.

If you forego Razor entirely, you may wish to use alternate ways of bundling assets (and updating references to the bundle in HTML). There are a number of ways, but the most popular involve using Grunt or Gulp build tasks, which run on Node.js. For example (using Grunt), see grunt-contrib-concat, grunt-contrib-uglify, grunt-rev, and grunt-usemin.

Here is a link using Grunt and a variety of the aforementioned tasks to accomplish all of the things Bundles do without using Bundles or Razor.

Brief summary of the article follows (your mileage may vary):

  • Create package.json (npm init can create this for you).
"grunt": "~0.4.1",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-uglify": "~0.2.7",
"grunt-contrib-cssmin": "~0.7.0",
"grunt-usemin": "~2.0.2",
"grunt-contrib-copy": "~0.5.0",
"grunt-rev": "~0.1.0",
"grunt-contrib-clean": "~0.5.0"
  • Create Gruntfile.js module.exports = function (grunt) { grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), clean: ["dist", '.tmp'], copy: { main: { expand: true, cwd: 'app/', src: ['**', '!js/**', '!lib/**', '!**/*.css'], dest: 'dist/' }, shims: { expand: true, cwd: 'app/lib/webshim/shims', src: ['**'], dest: 'dist/js/shims' } }, rev: { files: { src: ['dist/**/*.{js,css}', '!dist/js/shims/**'] } }, useminPrepare: { html: 'app/index.html' }, usemin: { html: ['dist/index.html'] }, uglify: { options: { report: 'min', mangle: false } } }); grunt.loadNpmTasks('grunt-contrib-clean'); grunt.loadNpmTasks('grunt-contrib-copy'); grunt.loadNpmTasks('grunt-contrib-concat'); grunt.loadNpmTasks('grunt-contrib-cssmin'); grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks('grunt-rev'); grunt.loadNpmTasks('grunt-usemin'); // Tell Grunt what to do when we type "grunt" into the terminal grunt.registerTask('default', [ 'copy', 'useminPrepare', 'concat', 'uglify', 'cssmin', 'rev', 'usemin' ]); };
  • Edit your index.html (or whatever your main app bootstrap page is) so your CSS and JS assets are properly decorated for usemin and rev: <!-- build:css css/app-name.min.css --> <link rel="stylesheet" href="lib/bootstrap/bootstrap.min.css"/> <link rel="stylesheet" href="lib/font-awesome/font-awesome.min.css"/> <link rel="stylesheet" href="lib/toaster/toaster.css"/> <link rel="stylesheet" href="css/app.css"/> <link rel="stylesheet" href="css/custom.css"/> <link rel="stylesheet" href="css/responsive.css"/> <!-- endbuild --> ... <!-- build:js js/app-name.min.js --> <script src="lib/jquery/jquery-1.10.2.min.js"></script> <script src="lib/bootstrap/bootstrap.min.js"></script> <script src="lib/angular/angular.min.js"></script> <script src="lib/angular/angular-animate.min.js"></script> <script src="lib/angular/angular-cookies.min.js"></script> <script src="lib/angular/angular-resource.min.js"></script> <script src="lib/angular/angular-route.min.js"></script> <script src="lib/fastclick.min.js"></script> <script src="lib/toaster/toaster.js"></script> <script src="lib/webshim/modernizr.min.js"></script> <script src="lib/webshim/polyfiller.min.js"></script> <script src="js/app.js"></script> <script src="js/services.js"></script> <script src="js/controllers.js"></script> <script src="js/filters.js"></script> <script src="js/directives.js"></script> <!-- endbuild -->

Now you have a Grunt build task that will look at your page for any asset blocks and concatenate/uglify the individual files referenced therein, and then replace the links in that block with one link to a single cache-busted file. This gets you what you had with Bundles.

During development, you don't need to do anything except add or remove assets from these blocks. For production, you just need to run your grunt build task before you package up or deploy your application.

If you're starting from scratch with JS task runners, you're better off with gulp or broccoli. Both have the same extent of plugin support at this point (including minification and revving), but are far better in terms of performance and programming paradigms.

c# - How do I bundle assets in ASP.NET MVC for use in Angular without ...

c# asp.net-mvc angularjs razor bundle
Rectangle 27 10

I answered a similar question a while ago. Basically, the best way would be to use the class HttpValueCollection, which the QueryString property actually is, unfortunately it is internal in the .NET framework. You could use Reflector to grab it (and place it into your Utils class). This way you could manipulate the query string like a NameValueCollection, but with all the url encoding/decoding issues taken care for you.

HttpValueCollection extends NameValueCollection, and has a constructor that takes an encoded query string (ampersands and question marks included), and it overrides a ToString() method to later rebuild the query string from the underlying collection.

I have read your post, and it sounds great. Thanks for your answer, i ll try it and get back

Not sure if this was the only method available in 2009 but there's another way without reflection in another answer for this question: stackoverflow.com/a/7530346/169034

.net - How can i remove item from querystring in asp.net using c#? - S...

c# .net asp.net query-string
Rectangle 27 10

I answered a similar question a while ago. Basically, the best way would be to use the class HttpValueCollection, which the QueryString property actually is, unfortunately it is internal in the .NET framework. You could use Reflector to grab it (and place it into your Utils class). This way you could manipulate the query string like a NameValueCollection, but with all the url encoding/decoding issues taken care for you.

HttpValueCollection extends NameValueCollection, and has a constructor that takes an encoded query string (ampersands and question marks included), and it overrides a ToString() method to later rebuild the query string from the underlying collection.

I have read your post, and it sounds great. Thanks for your answer, i ll try it and get back

Not sure if this was the only method available in 2009 but there's another way without reflection in another answer for this question: stackoverflow.com/a/7530346/169034

.net - How can i remove item from querystring in asp.net using c#? - S...

c# .net asp.net query-string
Rectangle 27 19

The token generated by UserManager in asp.net idebtity usually contains "+" characters which when passed as a query string get changed into " " (space) in the URL. In your ResetPassword ActionResult replace " " with "+" like this:

var code = model.Code.Replace(" ", "+");
//And then change the following line 
UserManager.ResetPasswordAsync(user.Id, model.Code, model.Password);
//To this one so it uses the code(spaces replaced with "+") instead of model.Code
UserManager.ResetPasswordAsync(user.Id, code, model.Password);

That should do the trick I had the same problem and found the answer here.

For me, this worked when the UrlEncode/Decode as described in other answers didn't.

i also the same issue i can't getting '==' in the last end from code so how can handle this i am code send via query string in the mail and i m also try this WebUtility.UrlEncode(code) in the mail send and getting time WebUtility.UrDecode(Model.code) using this but still getting issue and end of getting invalid token.

@Mansoor Would you have any suggestion for my this post. I tried your above suggestion but it did not work.

Token invalid on reset password with ASP.NET Identity - Stack Overflow

asp.net-mvc
Rectangle 27 1

import java.io.File

 import pavlosgi.freecli.core.all._
 import pavlosgi.freecli.config.all._
 import pavlosgi.freecli.command.all._

 object Git extends App {
   case class CommitConfig(all: Boolean, message: String)
   val commitCommand =
     cmd("commit") {
       takesG[CommitConfig] {
         O.help --"help" ::
         flag --"all" -'a' -~ des("Add changes from all known files") ::
         O.string -'m' -~ req -~ des("Commit message")
       } ::
       runs[CommitConfig] { config =>
         if (config.all) {
           println(s"Commited all ${config.message}!")
         } else {
           println(s"Commited ${config.message}!")
         }
       }
     }

   val rmCommand =
     cmd("rm") {
       takesG[File] {
         O.help --"help" ::
         file -~ des("File to remove from git")
       } ::
       runs[File] { f =>
         println(s"Removed file ${f.getAbsolutePath} from git")
       }
     }

   val remoteCommand =
    cmd("remote") {
      takes(O.help --"help") ::
      cmd("add") {
        takesT {
          O.help --"help" ::
          string -~ des("Remote name") ::
          string -~ des("Remote url")
        } ::
        runs[(String, String)] {
          case (s, u) => println(s"Remote $s $u added")
        }
      } ::
      cmd("rm") {
        takesG[String] {
          O.help --"help" ::
          string -~ des("Remote name")
        } ::
        runs[String] { s =>
          println(s"Remote $s removed")
        }
      }
    }

   val git =
     cmd("git", des("Version control system")) {
       takes(help --"help" :: version --"version" -~ value("v1.0")) ::
       commitCommand ::
       rmCommand ::
       remoteCommand
     }

   val res = parseCommandOrFail(args)(git).run
 }

scala - Best way to parse command-line parameters? - Stack Overflow

scala command-line command-line-parsing