Skip to content

Add migration guideline document from v1.9.x to 2.x to wiki #318

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

Closed
moh-hassan opened this issue Aug 30, 2018 · 1 comment
Closed

Add migration guideline document from v1.9.x to 2.x to wiki #318

moh-hassan opened this issue Aug 30, 2018 · 1 comment

Comments

@moh-hassan
Copy link
Collaborator

There are many applications which are still using v1.9 and need to migrate to v2.x.
The migration guideline may minimize the effort of change in the application source code.

Welcome to the contributors to comment on this issue and add their guidelines.

@moh-hassan
Copy link
Collaborator Author

moh-hassan commented Aug 30, 2018

The following steps describe how to change the code in v1.9 to v2.x

  1. Change the DefaultValue in Option Attribute to Default

V1.9.x

	class Options
	{
	  [Option('p', "person-to-greet", DefaultValue = "World")]
	  public string PersonToGreet { get; set; }
	}

V2.x
change DefaultValue to Default

	class Options
	{
	  [Option('p', "person-to-greet", Default = "World")]
	  public string PersonToGreet { get; set; }
	}
  1. Change OptionList Attribute:

v1.9.x

	 class Options
	 {
	  [OptionList('t', "tags")]
	  public IList<string> Tags { get; set; }  

	}

V2.x

	class Options
	{
		[Option('t', Min = 1, Separator=':')]
		public IEnumerable<string> Tags { get; set; }
	}
  1. Change OptionArray Attribute to Option:
    v1.9.x

       class Options
      {
     	[OptionArray('c', "Cas")]
        public string[] NameCase { get; set; }
      }	
    

V2.x

	class Options
	 {
		[Option('c', Min = 1)]
		public IEnumerable<string> NameCase { get; set; }		 
	}
  1. Change ValueList:

In v1.9.x

        [ValueList(typeof(List<string>))]
        public IList<string> DefinitionFiles { get; set; }

Is converted to:
[Value(0)]
public IEnumerable DefinitionFiles { get; set; }

  1. All collection like IList is converted to IEnumerable

  2. ParserState is no longer used, remove it

            [ParserState]
          public IParserState LastParserState { get; set; }
    

7)[HelpOption] Attribute is no longer used , remove or comment it.

  1. calling parser

            if (parser.ParseArgumentsStrict(args, options, () => Environment.Exit(-2)))
     	 if (parser.ParseArgumentsStrict(args, options, () => Environment.Exit(-2)))
         {
             Run(options);
         }
    

Is converted to:

         CommandLine.Parser.Default.ParseArguments<Options>(args)
	 .WithParsed<Options> (o=> Run(o))
	 .WithNotParsed<Options> (errors=> HandleParseError(errors));

Or use the MapResult, for example:

          //call parser	
       var parserResult= CommandLine.Parser.Default.ParseArguments<Options>(args)
               .MapResult(
             (opts) => RunOptionsAndReturnExitCode(opts),	 //in case parser success
            errs => HandleParseError(errs));  //in  case parser fail
  1. ParserState is no longer used.

see migrated example:
The version 1.9 source code is converted to 2.5 version

Read getting start for using v2.x

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

No branches or pull requests

1 participant